反序列化json C# [英] Deserializing json C#
本文介绍了反序列化json C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些代码,它们从api调用后返回json数据.数据采用以下格式:
I have code that returns json data from a post api call. The data is in the below format:
{"data":[{"name":"123","pwd":123},{"name":"456","pwd":456},{"name":"789","pwd":789}]",duration":5309,"query":"myquery","timeout":300}
要反序列化上面的json,我编写了以下代码:
To deserialise the above json, I have written the following code:
Product myprod = JsonConvert.DeserializeObject<Product>(result);
var results = myprod.result;
我的数据仍为null,count = 0.谁能帮我解决我哪里出问题了?
My data remains null with count=0. Could anyone help me with where am I going wrong ?
推荐答案
首先,您的json无效.这是相同的,但已修复.
First your json is invalid. Here is the same one but with fixes.
{"data":[{"name":"123","pwd":123},{"name":"456","pwd":456},{"name":"789","pwd":789}],"duration":5309,"query":"myquery","timeout":300}
使用此json模型应如下所示:
And with this json model should look like this:
public class Rootobject
{
public Datum[] data { get; set; }
public int duration { get; set; }
public string query { get; set; }
public int timeout { get; set; }
}
public class Datum
{
public string name { get; set; }
public int pwd { get; set; }
}
这篇关于反序列化json C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文