vb.net - Using json.net, how do I query within embedded arrays? -


first, i'm referencing this: http://james.newtonking.com/json/help/index.html?topic=html/selecttoken.htm

i'm using json.net

if post response returns following:

{     "success_count": 1,     "error_count": 0,     "data": [         {             "status": "example status",             "member_rating": 42          }     ] } 

and i've stored variable called "as_read"

i can following:

dim as_readjobj jobject = jobject.parse(as_read) dim as_successcountvalue = as_readjobj.property("success_count").value dim as_errorcountvalue = as_readjobj.property("error_count").value 

what can't seem understand how query value of status.

i've tried:

dim as_subscribestatus = as_readjobj.selecttoken("data[0].status").value dim as_subscribestatus = as_readjobj.property("data")("status").value 

and few other methods. seems i'm blind obvious, i'm new vb.net , started using json library.

thank you!


update: figured out.

i accepted answer, solution worked perfectly. figured out original problem. following works:

as_subscribestatus = as_readjobj.selecttoken("data[0].status").tostring 

i guess didn't understand inner workings of selecttoken enough. have 2 solutions. awesome.

you can use list of jtoken , iterate through items of list extract information want, including embedded arrays.

dim asread string = "{""success_count"": 1,""error_count"": 0,""data"": [{""status"": ""example status"",""member_rating"": 42}]}"          dim as_readjobj jobject = jobject.parse(asread)          dim results list(of jtoken) = as_readjobj.children().tolist          dim as_successcountvalue string         dim as_errorcountvalue string         dim status string = ""         dim member_rating string = ""          each item jproperty in results             item.createreader()             select case item.name                 case "success_count"                     as_successcountvalue = item.value.tostring                 case "error_count"                     as_errorcountvalue = item.value.tostring                 case "data"                     each subitem jobject in item.values                         status = subitem("status")                         member_rating = subitem("member_rating")                     next             end select         next 

i've edited code another question here in so. have not yet tried use .selecttoken code above should fulfill requirements supplied.

note:

i've used string status , member_rating whereas should list of string.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -