0

I am convert Json to Json String.

string callbackResponse = Newtonsoft.Json.JsonConvert.SerializeObject(result);

Getting result like :

 {
  "data": "{\r\n  \"DemoData\": {\r\n    \"value\": \"value1\"\r\n}",
  "Status_cd": 1
}

I want Result Like :

 {
  "data": {
    "DemoData": {
      "Value": "value1"
    },
    "Status_cd": "1"
  }
}

alos try with :

`Newtonsoft.Json.JsonConvert.DeserializeObject<string>(result`)

but not working for me.here result is a dynamic parameter.

need to save json in String but in unescape format can anyone help please?

  • 2
    Your desired result is not valid JSON. So no, unless you are willing to accept invalid json, nobody can help. And also the result you are getting does seem a bit off. Seems like `result.data` is a string and not an object. Please show the definition of your `result` object – derpirscher May 10 '21 at 13:41
  • Hello, first question is what is result. And just for clarification, you mean to get result like: {"data":{"value":11},"status_cd":1}? – g_bor May 10 '21 at 13:43
  • update my question with valid json.Please check if solution is possible. – Nimisha Prajapati May 11 '21 at 06:50
  • 3
    It seems you are double-serializing, you serialized something, stuffed the resulting json into `data` property and then serialize the object with that property. Perhaps you need to make `data` have the type of whatever you serialized into it instead. – Lasse V. Karlsen May 11 '21 at 07:02
  • You could apply `[JsonConverter(typeof(RawConverter))]` to the `data` property, where `RawConverter` comes from [this answer](https://stackoverflow.com/a/40539360/3744182) to [How can I serialize and deserialize a type with a string member that contains “raw” JSON, without escaping the JSON in the process](https://stackoverflow.com/q/40529125/3744182). In fact I think this may be a duplicate, agree? – dbc May 12 '21 at 16:18

0 Answers0