By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,035 Members | 1,471 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,035 IT Pros & Developers. It's quick & easy.

Looping Through JSON Response

100+
P: 116
Hi,

I am getting data from a web service. This is no problem. The returned JSON data is, say, as follows.

[
{
"jsonrpc":"2.0",
"result":[
{
"playerData":{
"number":"7",
"name":"Ronaldo"
},
"teamName":"Real Madrid"
},
{
"playerData":{
"number":"10",
"name":"Messi"
},
"teamName":"Barcelona"
}
],
"id":1
}
]

I am then deserializing it with the following line.

Expand|Select|Wrap|Line Numbers
  1. Dim playerresp = JsonConvert.DeserializeObject(Of Result)(responseFromServer)
  2.  
I have classes set up for playerData, teamName, number and name.

I know that what I need is like playerresp.playerData.name etc

But how do I loop through the players listed? Ie, so I can write them as

Real Madrid: Ronaldo (7)
Barcelona: Messi (10)


This is no doubt fairly straightforward but I'm struggling with the simple part having done the hard part....
Jan 30 '14 #1

✓ answered by robertybob

Ok I just removed the leading and trailing [ from the response before Deserializing and can get some data. Doesn't seem to be another way to do this so will suffice.

Share this Question
Share on Google+
2 Replies


100+
P: 116
Obviously not straightforward then...... no-one knows how to loop through a JSON response?
Jan 31 '14 #2

100+
P: 116
Ok I just removed the leading and trailing [ from the response before Deserializing and can get some data. Doesn't seem to be another way to do this so will suffice.
Jan 31 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.