0

Trying to get some information about a youtube video:

http://gdata.youtube.com/feeds/api/videos/BDQqSnSEuyk?v=2&alt=jsonc&callback=storeInfo

The result is JSON.

I try using deserialize it with JSON.net:

JObject JObj = (JObject)JsonConvert.DeserializeObject(gDataResult);

I get this error:

Error parsing comment. Expected: *, got /. Path '', line 1, position 1.

It is because of the single // comment.

Alvin
  • 8,219
  • 25
  • 96
  • 177
  • possible duplicate of [How can i read json with comment with Json.NET](http://stackoverflow.com/questions/10316997/how-can-i-read-json-with-comment-with-json-net) – Evan Trimboli Nov 28 '13 at 13:20
  • Regex.Replace(subjectString, ".*//.*$", "$1/*$2*/"); not working, has tried it. – Alvin Nov 28 '13 at 13:22
  • @EvanTrimboli: this is not duplicate, the target thread has nothing to do with JSON-P which the URL points at. – quetzalcoatl Nov 28 '13 at 13:29

1 Answers1

0

You have to be more careful when reading the data file. This is not JSON. This is JSON-P. Even the URL you provided suggests that: note the callback=storeInfo at the end.

The JSON-P differs from JSON in that the object is wrapped in a function call:

// API callback
storeInfo({"apiVersion":"2.1","..... }}});

To be a plain JSON, it needs to be just

// API callback
 {"apiVersion":"2.1","..... }}};

With this serivce, just use an url of http://gdata.youtube.com/feeds/api/videos/BDQqSnSEuyk?v=2&alt=jsonc without the 'callback' section and you'll get a normal JSON response.

quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107