bill bill - 1 year ago 120
JSON Question

how to convert a string with equal "=" sign to json in c#

I have following string, this returns from the web service


I want to convert this in to json like below

"Status": "Success",
"PNR": "76UUEI78787870",
"Customer_Ref": "89511133545"

how can I do that.

Answer Source
var str = "Status=Success,PNR=76UUEI78787870,Customer_Ref=89511133545";
var vals = str.Split(',');
var json = "{" +
                vals.Select(val => val.Split('=')).Select(s => string.Format("\"{0}\": \"{1}\"", s[0], s[1]))) +
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download