Answer the question
In order to leave comments, you need to log in
JSON in C#, how to deserialize and use?
There is, for example, this line:
{
"status": "ok",
"count": 1,
"data": [
{
"nickname": "The_IzeBerg",
"account_id": 11545443
}
]
}
Answer the question
In order to leave comments, you need to log in
1) Download dll james.newtonking.com/json
from here
2) Connect to the project
3) Write JObject o = JObject.Parse(jsonString);
4) Get o["data"]["account_id"] (like this)
Absolutely for beginners mustknowthat.blogspot.ru/2013/06/json-c.html?m=1
Use the library james.newtonking.com/json You
can connect the library through NuGet: RMB on References, Manage NuGet packages and JSON.NET write in the search. Well, or take the DLL from the site and in the same place through Add Reference ... specify.
Something like this:
using Newtonsoft.Json.Linq;
...
dynamic root = JObject.Parse(json);
int id = root.data[0].account_id;
If this is ASP MVC and you need to get the values in the controller action, then it is worth declaring the parameters with the desired type in the function definition, everything will be parsed by itself. for example
public void SaveData(int account_id, string nickname)
{
//process data
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question