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

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

代码如下:

//{"code":200,"检测编号":"JC1810231520411","message":"OK"}
string resp = ...
JObject respObj = new JObject(resp); //报错

格式正确的json字符串却无法转换为JObject,原因是什么?

自己想明白了,原来JObject本来就不是这样创建的,正确的方法如下:

string resp = ...
JObject respObj = (JObject)JsonConvert.DeserializeObject(resp);

问题解决。