Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.4k 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 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...