首页 > 编程知识 正文

c# jobject 解析

时间:2023-05-05 12:40:11 阅读:237910 作者:4948

下载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;}bldxtz = new SearchFaceMatchInfo();SearchFaceMatchInfo.log_id = result.Value<string>("log_id");//log_idSearchFaceMatchInfo.timestamp = result.Value<string>("timestamp");//timestampSearchFaceMatchInfo.cached = result.Value<string>("cached");//cachedSearchFaceMatchInfo.cached = result["result"]["face_token"].ToString();//face_tokenJArray res = result["result"].Value<JArray>("user_list");JObject j = JObject.Parse(res[0].ToString());SearchFaceMatchInfo.group_id = j.Value<string>("group_id");//group_idSearchFaceMatchInfo.user_id = j.Value<string>("user_id");//user_idSearchFaceMatchInfo.user_info = j.Value<string>("user_info");//user_infoSearchFaceMatchInfo.score = j.Value<float>("score");//score

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。