c# - How to parse Twitter Trends Json response -


i trying parse following json access name property. having difficulty.

 {[   {     "trends": [       {         "name": "#penaltypointsforpricks",         "url": "http://twitter.com/search?q=%23penaltypointsforpricks",         "promoted_content": null,         "query": "%23penaltypointsforpricks",         "events": null       },       {         "name": "#sometimesiwishthat",         "url": "http://twitter.com/search?q=%23sometimesiwishthat",         "promoted_content": null,         "query": "%23sometimesiwishthat",         "events": null       },       {         "name": "#1000daysof1d",         "url": "http://twitter.com/search?q=%231000daysof1d",         "promoted_content": null,         "query": "%231000daysof1d",         "events": null       },       {         "name": "#ireland",         "url": "http://twitter.com/search?q=%23ireland",         "promoted_content": null,         "query": "%23ireland",         "events": null       },       {         "name": "#savita",         "url": "http://twitter.com/search?q=%23savita",         "promoted_content": null,         "query": "%23savita",         "events": null       },       {         "name": "twitter",         "url": "http://twitter.com/search?q=twitter",         "promoted_content": null,         "query": "twitter",         "events": null       },       {         "name": "cork",         "url": "http://twitter.com/search?q=cork",         "promoted_content": null,         "query": "cork",         "events": null       },       {         "name": "facebook",         "url": "http://twitter.com/search?q=facebook",         "promoted_content": null,         "query": "facebook",         "events": null       },       {         "name": "boston",         "url": "http://twitter.com/search?q=boston",         "promoted_content": null,         "query": "boston",         "events": null       },       {         "name": "will",         "url": "http://twitter.com/search?q=will",         "promoted_content": null,         "query": "will",         "events": null       }     ],     "as_of": "2013-04-18t18:34:45z",     "created_at": "2013-04-18t18:29:40z",     "locations": [       {         "name": "dublin",         "woeid": 560743       }     ]   } ]} 

i had following suggestion returns null reference exception during run time.

 var twitterobject = jtoken.parse(jsonstring);         var trendsarray = twitterobject.children<jproperty>().firstordefault(x => x.name == "trends").value;           foreach (var item in trendsarray.children())          {             var itemproperties = item.children<jproperty>();             //you foreach or linq here depending on need value             var myelement = itemproperties.firstordefault(x => x.name == "url");             var myelementvalue = myelement.value; ////this jvalue type         } 

anyone have suggestions how parse json response each individual "name"

i able names using this.

dynamic dynobj = jsonconvert.deserializeobject(jsonstring);  foreach (var trend in dynobj[0].trends) {     console.writeline(trend.name); } 

it'd better write classes json objects if plan grab more name, hope helps.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -