Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
Quote:
Unexpected character encountered while parsing value: . Path '', line 0, position 0.


The Jsnon Response Data Looks like this
Quote:
{"Id":"Null","Name1":"sample1","Name2":"sample2","Name3":"Sample3"}


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"]);
Posted
Updated 7-Apr-17 0:36am
v3
Comments
Richard MacCutchan 7-Apr-17 3:38am    
What is in the data?
Vixita-i50 7-Apr-17 4:31am    
Data id the Json Response. i.e, looks like:
{"Id":Null,"Name1":"sample1","Name2":"sample2","Name3":"Sample3"}
Richard MacCutchan 7-Apr-17 4:48am    
The error message does not seem consistent with the text that is received. Trying that text in JavaScript it parses OK.
Vixita-i50 7-Apr-17 6:35am    
Can I get what you did and How you did it?

1 solution

{"Id":Null,"Name1":"sample1","Name2":"sample2","Name3":"Sample3"}

It is not a valid JSON, it should be either

{"Id":"Null","Name1":"sample1","Name2":"sample2","Name3":"Sample3"}

or
{"Id":null,"Name1":"sample1","Name2":"sample2","Name3":"Sample3"}
 
Share this answer
 
Comments
Vixita-i50 7-Apr-17 6:33am    
yes it is:
{"Id":"Null","Name1":"sample1","Name2":"sample2","Name3":"Sample3"}.
How do I resolve that?
Karthik_Mahalingam 7-Apr-17 6:42am    
check how you are passing from UI, you will have to correct it there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900