0

I'm having to deal with data I'm sent and have no control over the source. The data I have is json, but is sent within other JSON as a string, so its abit of a mess, example being:

"{\u0022Products\u0022:[{\u0022ProductName\u0022:\u0022Foo Bar\u0022,\u0022SomethingElse\u0022:null},{\u0022ProductName\u0022:\u0022Foo Bar Pro\u0022,\u0022AnotherThing\u0022:null}],\u0022CustomerRequiredDate\u0022:\u00222022-10-27T16:05:58.4528008\u002B01:00\u0022}"

I want to deserilaize this into a class I have for the data it holds, which cleaned up should be:

{"Products":[{"ProductName":"Foo Bar","SomethingElse":null},{"ProductName":"Foo Bar Pro","AnotherThing":null}],"CustomerRequiredDate":"2022-10-27T16:05:58.4528008+01:00"}"

My current solution is to find a replace the ascii, but this only handles ascii I currently know it may contain, but it could have anything as I don't control the source.

string cleanString = Order.OrderState.Replace("\u0022", "\"").Replace("\u002B", "+");
OrderState = JsonSerializer.Deserialize<OrderState>(cleanString );
Vereonix
  • 1,341
  • 5
  • 27
  • 54

0 Answers0