Md. Parvez Alam Md. Parvez Alam - 1 year ago 114
JSON Question

Single string in json to deserialze c#

I have following string in JSON

string IDS = "{\"IDS\":\"23,24,25,28\"}"

Now I need to convert this into c# string

I tried this

string id = new JavaScriptSerializer().Deserialize<string>(IDS);

I want to get back this comma separated string in a string, but it throws error

No parameterless constructor defined for type of 'System.String

Any help what to do ?


Answer Source

It's because your json string is a Dictionary. Try it with something like this

var result = new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(IDS);
var mystring = result["IDS"];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download