This question may be duplicate, but I didn't find a satisfactory answer, so that's why I am raising the question.
I am working on serialization of dynamic objects. When I serialize a dynamic object, the API returns the response as
"{\"firstname\":\"prasanthi\",\"lastname\":\"kota\"}"
I didn't want to use string.Replace or RegexPattern. Is there any other way to do this?
I have tried JavaScriptSerializer, but it adds in quote marks with escape marks (\"
).
Here is my code:
dynamic d = new ExpandoObject();
d.firstname = "prasanthi";
d.lastname = "kota";
string serialized_info = JsonConvert.SerializeObject(d);
Update:
I am using serialized_info in another part of my code.I don't want slashes there. So, I want to remove slashes before.
I have tired which are mentioned in comments
dynamic x = new { firstname = "prasanthi", lastname = "kota" }; var serialized_info = JsonConvert.SerializeObject(x,Formatting.Indented);
this is displaying
"{\r\n \"firstname\": \"prasanthi\",\r\n \"lastname\": \"kota\"\r\n}"
I don't think this is the answer to my question. Can you suggest me in any other way to do other than string.replace