Skip to content Skip to sidebar Skip to footer

How Can I Parse Json String Without The Opening And Closing String Quotes?

How can i parse the following json string without the opening and closing quotes? Its seems like javascript JSON.parse function is parsing the string with the quotes! hence throws

Solution 1:

Replace the opening and closing quotes, and then parse the string:

s = s.replace(/^"|"$/g, '');
var jsonDoc = JSON.parse(s);

Additionally, file a bug report with the author of the program or library that emits malformed JSON.


Solution 2:

you should probably remove the outer quotes from your string...

mystring = mystring.replace(/^"|"$/g,'')

Solution 3:

1.This should be your JSON format otherwise, it WILL NOT be parsed properly by JSON.parse

[
        {
            "pk": 1,
            "model": "pms.category",
            "fields": {
                "name": "Rent",
                "add_date": "2011-07-28 01:33:21",
                "agent": 3,
                "category_type": "I",
                "add_user": 3,
                "desc": "Rent"
            }
        },
        {
            "pk": 2,
            "model": "pms.category",
            "fields": {
                "name": "Deposit Rent",
                "add_date": "2011-07-28 01:33:21",
                "agent": 3,
                "category_type": "I",
                "add_user": 3,
                "desc": "Rent Deposit"
            }
        }
    ]

2.Include json2.js from the github repository inbetween your head tags.


Post a Comment for "How Can I Parse Json String Without The Opening And Closing String Quotes?"