0

Possible duplicates

Im trying to parse a website and one request returns such content:

for (;;);{"__ar":1,"payload":null,"domops":[["appendContent","^div.fbProfileBrowserListContainer",true,{"__html":"\u003Cdiv ... ]

Here is image : enter image description here What type is it gzip or what? I need to parse it from c#, but can't get response. Response is always empty or question marks. What parameter need to add in header request to read response. Can't figure it out.

Community
  • 1
  • 1
  • How can i get it from httpwebrequest? Is it possible? – Nika Javakhishvili Dec 21 '15 at 09:48
  • Simply remove it from the response (with a `replace` for example) before you pass the response to a Json parser. – RobIII Dec 21 '15 at 09:49
  • Okey i got it, Now i need online parser for it to see actual content – Nika Javakhishvili Dec 21 '15 at 09:53
  • I got the response correctly, but how to parse it and get specific information – Nika Javakhishvili Dec 21 '15 at 09:53
  • Use [`Replace`](https://msdn.microsoft.com/en-us/library/fk49wtc1(v=vs.110).aspx), [`Substring`](https://msdn.microsoft.com/en-us/library/system.string.substring(v=vs.110).aspx) or any other method you prefer. Even a [`Regex`](https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx) like `^for \(;;\);` will do. – RobIII Dec 21 '15 at 09:54

2 Answers2

2

Try something like:

//Get actual response from server; here we use a hardcoded response
var response = "for (;;);{\"__ar\":1,\"payload\":null,\"domops\"....";

var fixedresponse = response.Substring(9);

Or, alternatively:

var fixedresponse = new Regex(@"^for \(;;\);").Replace(response, string.Empty);

Or...

var fixedresponse = response.Substring(response.IndexOf("{"));

Or, alternatively (but less 'safe' since the actual JSON content may also contain an empty for-loop):

var fixedresponse = response.Replace("for (;;);", string.Empty);

...or any other string operation you can think of actually; whatever gets the job (removing the stuff before the actual JSON) done.

You can read the "possible duplicates" I editted in your question for an explanation on why the empty for-loop is there in the first place.

RobIII
  • 8,488
  • 2
  • 43
  • 93
0

You can just do it like this:

'for (;;);{"__ar":1,"payload":null,".....'.substr(9);

As one comment already stated out, this is to prevent code injection. Everything after the for loop seems to be valid json. So just use the output of the code above with your json parser.

Dennis Stücken
  • 1,296
  • 9
  • 10