简体   繁体   中英

Extracting JSON from JSONP

I am parsing a JSON file using C#. Here is what I got from the server:

loadData([ 
{"id":"id1","nm":"name1"}, 
{"id":"id2","nm":"name2"}, 
{"id":"id3","nm":"name3"}
]);

This is not the entire string, as I have deleted some of the values to make it appear more straightforward.

As you can see, this JSON is not parseable because it ends with semicolon ( ; ) and has a bunch of other issues which need to be fixed.

Now that I have this data, is there any workaround I can do on the client side to parse this JSON?

The server gave you more than the JSON file. It gave you loadData(jsonData); with jsonData looking like this :

[ 
    {"id":"id1","nm":"name1"}, 
    {"id":"id2","nm":"name2"}, 
    {"id":"id3","nm":"name3"}
]

So you will have to parse this to extract the JSON file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM