How to parse Escaped JSON Array in Net Core

I have this JSON that I get from API, I have trouble with Parsing the JSON to get the value I want this is the JSON

["{\"UPDATE_TYPE\":\"NOTE_ADDED\",\"UPDATE_TEXT\":\"Notenya begini\",\"UPDATE_TIME\":\"Fri, Dec 4, 17:02\",\"UPDATE_TIME_EPOCH\":1607076127834,\"ATTACHMENT\":\"\"}","{\"UPDATE_TYPE\":\"STATUS_UPDATED\",\"UPDATE_TEXT\":\"Complete\",\"UPDATE_TIME\":\"Fri, Dec 4, 17:02\",\"UPDATE_TIME_EPOCH\":1607076127840,\"ATTACHMENT\":\"\"}"]

I already tried to Deserialize it twice to remove the encoding. And I try to use Regex too but I still get an error when tried to parse using Newtonsoft JAray.Parse. I never encounter JSON like this before.
any suggestion to remove the encoding and parse the value from that JSON?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

  1. Remove double quotes between [ and {, same at the end of the string.
  2. Remove the in json string.

This is the specific step, intercepted part of the json string.

        var str = "["{\"UPDATE_TYPE\":\"NOTE_ADDED\",\"UPDATE_TEXT\":\"Notenya begini\",\"UPDATE_TIME\":\"Fri, Dec 4, 17:02\"}"]";

        Regex rg = new Regex("(?<=(" + "{" + "))[.\s\S]*?(?=(" + "}" + "))", RegexOptions.Multiline | RegexOptions.Singleline);
        var lstr= rg.Match(str).Value;
        
        var jstr = "[{" + lstr + "}]";
        var model=jstr.Replace(@"", "");
        var result=JsonConvert.DeserializeObject<List<Model>>(model);

Model.

public class Model
{
    public string UPDATE_TYPE { get; set; }
    public string UPDATE_TEXT { get; set; }
    public string UPDATE_TIME { get; set; }
}

How to parse Escaped JSON Array in Net Core


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x