Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.

https://blog.csdn.net/zhouyingge1104/article/details/83307637json

C#项目中使用NewtonSoft.json,报错提示:.net

Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject.code

代码以下:blog

//{"code":200,"检测编号":"JC1810231520411","message":"OK"}
string resp = ...
JObject respObj = new JObject(resp); //报错
格式正确的json字符串却没法转换为JObject,缘由是什么?字符串

本身想明白了,原来JObject原本就不是这样建立的,正确的方法以下:string

string resp = ...
JObject respObj = (JObject)JsonConvert.DeserializeObject(resp);
问题解决。
---------------------
做者:zhouyingge1104
来源:CSDN
原文:https://blog.csdn.net/zhouyingge1104/article/details/83307637
版权声明:本文为博主原创文章,转载请附上博文连接!方法

相关文章
相关标签/搜索