{"sign":"1437be8f4b5b80b850056eb5d20c65de","message":"success","gameOrderNo":"6a2aa56a-afb1-40bb-8325-cbfeb6a015cc","status":"success","userId":"62ldajo2","thirdNo":"2022010122001481711453820045","gameCoin":"0","extInfo":"{"productId":"xxxxxxxxx"}","thirdAmount":"3000.00","channelNo":"110001","productId":"","currency":"coin"}
显然extInfo是错误的,没有转义的斜杠,Newtonsoft.Json的报错信息是 p. Path 'extInfo', line 1, position 224.
有没有办法把extInfo忽略掉,把其他数据解析出来。
试试这样 {"sign":"1437be8f4b5b80b850056eb5d20c65de","message":"success","gameOrderNo":"6a2aa56a-afb1-40bb-8325-cbfeb6a015cc","status":"success","userId":"62ldajo2","thirdNo":"2022010122001481711453820045","gameCoin":"0","extInfo":{"productId":"踩踩踩"},"thirdAmount":"3000.00","channelNo":"110001","productId":"","currency":"coin"}
这样肯定可以啊,我现在要求能解析错误的json数据
加一个
try
{
}
catch
{}
哈哈,如果只是针对这一种情况,实在不行,你可以用最笨拙的方式,那就是文本替换,替换后在做转换
jsonStr = jsonStr.Replace(""{"","{"");
jsonStr = jsonStr.Replace(""}"", ""}");
当然还可以写正则表达式来处理是最好
这样不就是一个完整的json格式了嘛