c# jobject 解析

下载Newtonsoft.Json,记得添加引用using Newtonsoft.Json.Linq;

Jobject的内容格式如下:关键是怎么把user_list中的内容提取出来

{

  "error_code": 0,
  "error_msg": "SUCCESS",
  "log_id": 3014595066,
  "timestamp": 1527234617,
  "cached": 0,
  "result": {
    "face_token": "49d58eacd7811e463429a1ae10b42173",
    "user_list": [
      {
        "group_id": "NR",
        "user_id": "1028867728",
        "user_info": "cactus0117",
        "score": 97.499450683594
      }
    ]
  }

}

//定义的类

public class SearchFaceMatchInfo
{
            public JObject OriginInfo;
            public string error_code;
            public string error_msg;
            public string log_id;
            public string timestamp;
            public string cached;
            public string face_token;
            public string group_id;
            public string user_id;
            public string user_info;
            public float score;
}

SearchFaceMatchInfo SearchFaceMatchInfo = new SearchFaceMatchInfo();

SearchFaceMatchInfo.log_id = result.Value<string>("log_id");//log_id
SearchFaceMatchInfo.timestamp = result.Value<string>("timestamp");//timestamp
SearchFaceMatchInfo.cached = result.Value<string>("cached");//cached
SearchFaceMatchInfo.cached = result["result"]["face_token"].ToString();//face_token

JArray res = result["result"].Value<JArray>("user_list");
JObject j = JObject.Parse(res[0].ToString());
SearchFaceMatchInfo.group_id = j.Value<string>("group_id");//group_id
SearchFaceMatchInfo.user_id = j.Value<string>("user_id");//user_id
SearchFaceMatchInfo.user_info = j.Value<string>("user_info");//user_info
SearchFaceMatchInfo.score = j.Value<float>("score");//score


  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值