Json.NET parsing issue with twitter API data

I have successfully used json.NET in projects for some time without any problems. Last night, I came across my first case where json.NET crashed while trying to parse the json data returned from what should be a reliable source: twitter API.

In particular, this code causes an error:

string sCmdStr = String.Format("https://api.twitter.com/1/users/lookup.json?screen_name={0}", sParam);
string strJson = _oauth.APIWebRequest("GET", sCmdStr, null);
JObject jsonDat = JObject.Parse(strJson);

In my case, the sParam line contained about 25 titles of numeric identifiers. The twitter API call succeeded, but the json.NET Parse call ended with the following error:

"Error reading JObject from JsonReader. The current JsonReader is not an object: StartArray"

Anyone else run into this? Does anyone know about this? I am at the dead stop until it resolves it.

+5
1

, , . JObject.Parse JArray.Parse. , :

string sCmdStr = String.Format("https://api.twitter.com/1/users/lookup.json?screen_name={0}", sParam);
string strJson = _oauth.APIWebRequest("GET", sCmdStr, null);
JArray jsonDat = JArray.Parse(strJson);

.

for(int x = 0; x < jsonDat.Count(); x++)
{
     JObject tweet = JObject.Parse(jsonDat[x].toString());
     string tweettext = tweet["text"].toString();
     //whatever else you want to look up
}
+8

All Articles