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("log_id");//log_id
SearchFaceMatchInfo.timestamp = result.Value("timestamp");//timestamp
SearchFaceMatchInfo.cached = result.Value("cached");//cached
SearchFaceMatchInfo.cached = result["result"]["face_token"].ToString();//face_token

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


你可能感兴趣的:(c# jobject 解析)