I have the following JSON string
{"fields": "{n "CurrentPage": 14,n "CurrentSubPageNo": 18,n "IsFileUpload": false,n "VisitedPages": [n 2,n 3,n 4,n 6,n 7,n 8,n 10,n 11,n 12,n 13,n 14n ]n}"}
How can I make it to be like the following in C#?
{"fields":{"CurrentPage":14,"CurrentSubPageNo":18,"IsFileUpload":false,"VisitedPages":[2,3,4,6,7,8,10,11,12,13,14]}}
I am using Newtonsoft.Json
and I do not know on how to achieve like the above result
Please do take a note that the value inside fields
can be dynamic (which the key and value inside it can be present or not), which is why deserialize to a class for the value inside fields
is not an option for me
Anyone knows on how to do it?
Thank you very much
2
Answers
your "fields" property of json object is serialized twice, so you need just parse it twice. You can put all code in one line
This is reasonably simple:
JObject
fields
, which should be a stringJObject
fields
to the parsed valueJObject
to a stringSample code – lacking error handling, of course: