JToken取出JSON中任何一个节点的值

 https://www.lmlphp.com/user/120373/article/item/1777247/

//string jSonStr = "{\"co_id\":10413817,\"shop_id\":11842588}";
//string jSonStr = "{\"Result22\":\"0\",\"Message\":\"数据保存失败\",\"ErrList\":[],\"SucessList\":[]}";
string jSonStr = "{\"adOrderId\":\"AD202207130030100040000184\",\"consigneeInfo\":{\"receiverAddress\":\"123456789\",\"receiverMobile\":\"\"},\"goodsList\":[{\"color\":\"充值\",\"discountDetails\":[{\"Name\":\"BOB\",\"Age\":\"88\"}],\"skuId\":\"1324515449706758145\",\"styleNo\":\"Q9001111060\"}],\"num\":1,\"orderId\":\"202207130030100040000184\",\"otherInfo\":{\"warehouseCode\":\"310104000000\"},\"paymentTime\":1657702070000,\"updateTime\":1657702130000}";
JObject obj = JObject.Parse(jSonStr);

JToken result = obj as JToken;
string ReName = "warehouseCode";
string para = "$.." + ReName;
var str = result.SelectToken(para);

 

通过SelectToken获取json集合中的指定的值:JToken result = o.SelectToken("$.Databases[?(@.Id == 2)]");

https://www.5axxw.com/questions/content/bdtg8p

 

posted @ 2022-08-28 22:03  ProZkb  阅读(417)  评论(0编辑  收藏  举报