How to remove parentheses from JSON at the beginning and at the end?

I have a Json Object, as if

({
    "result":[{
        "key":"value".....
    }]
})

I do not know how to remove parentheses from the beginning and end of JSON, for example (and ). Please guide me.

+4
source share
2 answers

I assume that you are trying to access JSONP data. Probably you need to add? Callback =? to your url

var url="http://www.somedata.com";
    $.getJSON(url+'?callback=?', function(json){
        //loop through deals
        $.each(json.people,function(i,dat){
            $("#todaycal").append("<li>"+dat.name+"  "+dat.caseNo+"</li>");
        });
        $("#todaycal").listview('refresh');
    });
+2
source

For me, I took your JSON as a sample. Entry below

var test = ({
            "result":[{
                "key":"value"
            }]
        });

Using JSON.stringify(test), you removed this thing (start and )End

Output as below

{"result":[{"key":"value"}]}
0
source

Source: https://habr.com/ru/post/1649142/


All Articles