Rodney Wormsbecher Rodney Wormsbecher - 1 month ago 13
C# Question

.net C# JArray how to get data out of it?

I am trying to consume an API service that will give me some data back in JSON that will then be used in a winForm Project.

I Used the following backend code:

var json = new WebClient().DownloadString (sURL);
var results = JsonConvert.DeserializeObject(json);

dynamic array = JArray.Parse(json);


reulting in the following data:

{
{"AppId": 1,
"applications": "C:\\Program Files (x86)\\Tencent\\WeChat\\WeChat.exe",
"recordId": 1,
"userId": 1}
}


So I expected I could use array["applications"] to get my data but it turned out i was wrong. Any help is appreciated.

Answer

assuming if this was your json:

[
{"AppId": 1, 
"applications": "C:\\Program Files (x86)\\Tencent\\WeChat\\WeChat.exe", 
"recordId": 1,            
"userId": 1}
]

you can use JArray a= JArray.Parse(json); and loop through.