我正在尝试使用下面的代码解析我的 json。我得到错误:
从 JsonReader 读取 JObject 时出错。路径 '',第 0 行,第 0 位置。
我认为这可能是因为我的 JSON 格式错误,所以我输出了它,它似乎没问题:
{
"serviceDeskId": "4",
"requestTypeId": "223",
"requestFieldValues": {
"summary": "test"
}
}
但现在我完全被困住了。谁能看到我哪里出错了?这真让我抓狂!!
正是在这一行上触发了错误:
var jsonresponse = JObject.Parse(response);
完整的代码片段:
req.ContentType = "application/json";
var json = JObject.Parse(
"{\"serviceDeskId\": \"4\",\"requestTypeId\": \"223\",\"requestFieldValues\": {\"summary\": \"" +
summary.Value + "\"}}");
jsonCheck = json.ToString();
using (var streamWriter = new StreamWriter(req.GetRequestStream()))
{
streamWriter.Write(json);
}
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
// Obtain a 'Stream' object associated with the response object.
Stream ReceiveStream = resp.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
String response = "";
// Pipe the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader(ReceiveStream, encode);
response = readStream.ReadToEnd();
// Release the resources of stream object.
readStream.Close();
// Release the resources of response object.
resp.Close();
var jsonresponse = JObject.Parse(response);
任何帮助,将不胜感激!