Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.3k views
in Technique[技术] by (71.8m points)

C#怎么解析这种类型的JSON数据

目前通过接口形式返回这样的数据:

{
    "code": 0,
    "msg": "OK",
    "data": [
        {"name": "John", age: 21},
        {"name": "Tom", age: 40}
    ]
}

保存数据的实体类:

public class Person
{
    public string Name;
    public string Age;
}

我想先判断code的值,0为成功时才解析data中的数据,试过用Json.Net,但它只支持完全匹配实体类的数据,像code,msg这些我不想包含在实体类里,请问这种形式的接口数据应该怎么解析?先用正则提取出来再进行解析吗,有没有类似js那样简单的方法,像jsonObject.data[0].name这样的,行业内一般采用的做法是什么呢,请大佬们指导一下,谢谢了~~~


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

已经解决了,升级最新的Json.Net就好了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...