本文介绍了解析json时遇到意外的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码反序列化了一个json Response:
string data = response.Content;
//将其反序列化为包含每个键及其值的对象
Dictionary< string,object> values = JsonConvert.DeserializeObject< Dictionary< string,object>>(data);
TextBox1.Text = Convert.ToString(values [values]);
但我收到的错误是:
Jsnon响应数据看起来像这样
我尝试过:
我试过使用以下代码解决它但它仍然给出相同的错误,
var settings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
MissingMemberHandling = MissingMemberHandling.Ignore
};
// var jsonModel = JsonConvert.DeserializeObject< Customer>(jsonString,settings);
Dictionary< string,object> values = JsonConvert.DeserializeObject< Dictionary< string,object>>(data,settings);
TextBox1.Text = Convert.ToString(values [values]);
解决方案
I deserialized a json Response with the following code:
string data = response.Content; //Deserializing it into an object that will contain each of the keys and their values Dictionary<string, object> values = JsonConvert.DeserializeObject<Dictionary<string, object>>(data); TextBox1.Text = Convert.ToString(values["values"]);
But I get error that says:
The Jsnon Response Data Looks like this
What I have tried:
I tried using the following code to resolve it but it still give the same error,
var settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore }; // var jsonModel = JsonConvert.DeserializeObject<Customer>(jsonString, settings); Dictionary<string, object> values = JsonConvert.DeserializeObject<Dictionary<string, object>>(data, settings); TextBox1.Text = Convert.ToString(values["values"]);
解决方案
这篇关于解析json时遇到意外的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!