我收到反序列化错误,但仅在Testserver上。 生产服务器上的相同代码可以工作。
发生以下错误: {“解析值时遇到意外字符:。路径”,第0行,位置0。”}
这是我从网络服务获得的json字符串。
{"success":true,"responses":[{"statusCode":0,"responseMessage":"Der Datensatz wurde erfolgreich unter dem Bookmark BD2797BB4D283AF2 gespeichert"},{"statusCode":0,"responseMessage":"Der Datensatz wurde erfolgreich unter dem Bookmark 05206DB94D283AF2 gespeichert"},{"statusCode":0,"responseMessage":"Der Datensatz wurde erfolgreich unter dem Bookmark 900349C04D283AF2 gespeichert"},{"statusCode":0,"responseMessage":"Der Datensatz wurde erfolgreich unter dem Bookmark ED492DC74D283AF2 gespeichert"}]}
几天前,它也在testserver上运行,但我不知道该错误在哪里。
Web服务调用:
var errorPositions = new List<SalesConditionErrorMesageDTO>();
string response = "";
var settings = JsonSetting.DefaultSerializerSettings;
string jsonDataString = JsonConvert.SerializeObject(
new DataSend()
{
Conditions = salesConditions
}, settings
);
HttpWebRequest request = CreatePostRequest(ServerConfiguration.ConditionsWrite, jsonDataString.Length);
request.Timeout = 7200000; //120 Minutes
Logger.Log("Save Conditions on:" + Environment.NewLine
+ request.RequestUri + Environment.NewLine
+ jsonDataString, LogSeverity.Information);
using (Stream webStream = request.GetRequestStream())
using (StreamWriter requestWriter = new StreamWriter(webStream, Encoding.ASCII))
{
requestWriter.Write(jsonDataString);
}
using (WebResponse webResponse = request.GetResponse())
using (Stream webStream = webResponse.GetResponseStream())
{
if (webStream != null)
{
using (StreamReader responseReader = new StreamReader(webStream))
{
response = responseReader.ReadToEnd();
var responseJson = JsonConvert.DeserializeObject<dynamic>(response);
if ((bool)responseJson.success)
{
foreach (dynamic responsePart in responseJson.responses)
{
if ((int)responsePart.statusCode == 2)
{
var errorPosition = new SalesConditionErrorMesageDTO(0, 0, responsePart.responseMessage);
}
}
}
}
}
else
{
throw new NullReferenceException("WebResponse.GetResponseStream() returned no WebStream object, so this is NULL.");
}
}