29
2019-10

C#一个很好用的JSON解析器

MojoUnityJson是使用C#实现的JSON解析器,仅依赖System.Collections.GenericSystem.TextSystem 三个命名空间,不用引入其他Dll文件,简单的JSON使用非常合适。


比如下面这个结构:

{
  "code": 1,
  "msg": "登录成功",
  "time": "1572234482",
  "data": {
    "userinfo": {
      "score": 2,
      "token": "4f10da93-8ec6-56b475befdf0",
      "user_id": 38,
      "createtime": 1572234482,
      "expiretime": 1572493682,
      "expires_in": 259200
    }
  }
}

使用方法:

string jsonString = "{\"code\":1,\"msg\":\"登录成功\",\"time\":\"1572198646\",\"data\":{\"userinfo\":{\"avatar\":\"data:image\\/svml;base64,PHN2Z4bWxu0Pjwvc3ZnPg==\",\"score\":2,\"token\":\"49d35a9d-bc5e-a1127e734c03\",\"user_id\":38,\"createtime\":1572198646,\"expiretime\":1572457846,\"expires_in\":259200}}}";
var jsonValue = Json.Parse(jsonString);
var userInfo = jsonValue.AsObjectGet("data").AsObjectGet("userinfo");
string token = userInfo.AsObjectGetString("token");
int expiretime = userInfo.AsObjectGetInt("expiretime");



源码:https://github.com/scottcgi/MojoUnityJson


« 上一篇下一篇 »

相关文章:

留言列表:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。