You must Sign In to post a response.
  • Category: ASP.NET

    How to parse json in

    Hello friends,
    I am in process to parse json.

    Once I store json in string, I get following string

    Json is

    {"firstName":"John", "lastName":"Doe"},
    {"firstName":"Anna", "lastName":"Smith"},
    {"firstName":"Peter", "lastName":"Jones"}

    It converts i c# string as

    string s="\":[\r\n {\"firstName\":\"John\", \"lastName\":\"Doe\"},\r\n {\"firstName\":\"Anna\", \"lastName\":\"Smith\"},\r\n {\"firstName\":\"Peter\", \"lastName\":\"Jones\"}\r\n]}\r\n\r\n"

    Although \r\n can be removed using

    string m = s.Replace(System.Environment.NewLine, string.Empty);

    But how to remove \ from whole string.

    "\":[ {\"firstName\":\"John\", \"lastName\":\"Doe\"}, {\"firstName\":\"Anna\", \"lastName\":\"Smith\"}, {\"firstName\":\"Peter\", \"lastName\":\"Jones\"}]}"

    Please share any code snippet if u have.

    Thanks and Regards
  • #763725
    Hai Navneet,
    You can use the code below to replace the '\' with the empty string as:

    string k = m.Replace('\',' ');

    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • #763734
    simple, just use replace method

    s = s.Replace(@"\", string.Empty);
    s = s.Replace("\\","");

    pl. let us know if you face any problem

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #763751

    I guess Prasad answer will help you to remove the back slash, if you still have issues then please let us know.

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #763813
    Following is the valid JSON

    {{"firstName":"John", "lastName":"Doe"},
    {"firstName":"Anna", "lastName":"Smith"},
    {"firstName":"Peter", "lastName":"Jones"}}

    By Nathan
    Direction is important than speed

Sign In to post your comments