数组:
{ "field':["field1":"value1","field2":"value2"], ["field1":"value1","field2":"value2"] }
如何在C#中解析上述json响应
在json您提供的字符串 不正确 的json格式,该json阵列应该是:
json
{"field":[ {"field1":"value1","field2":"value2"}, {"field1":"value1","field2":"value2"} ] }
您可以使用json.net将其转换:
json.net
var obj = JsonConvert.DeserializeObject(json);
该工具在nuget中也可用。
如果要使用强类型:
public class YourObject { public string Field1 { get; set; } public string Field2 { get; set; } } public class YourClass { public YourObject[] Field { get; set; } } var yourClass = JsonConvert.DeserializeObject<YourClass>(json);