接受服务器post信息后解析失败结果异常Null
原因:存在转义字符,导致解析失败
代码:
Stream st = httpResponse.GetResponseStream();
StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
string json = reader.ReadToEnd();
Debug.Log(json);
//加上这一步就能获取到正常的json
json = Regex.Unescape(json);
Debug.Log(json);
var tmp = JsonMapper.ToObject(json);
Debug.Log(tmp["respCode"].ToString());
我在 string json = reader.ReadToEnd() 时,输出正常结果,但是如果不加上Regex.Unescape(json);
会导致下面tmp输出报错NULL。
总结:接受服务器Json信息时注意1.编码格式 UTF-8是比较通用的。2.转义字符是否除去。
有用点个赞,看看多少人踩到这个坑了:)