How could I parse through this JSON object in JQuery?

This question already has an answer here:

  • Parse JSON in JavaScript? [duplicate] 16 answers
  • Access / process (nested) objects, arrays or JSON 18 answers

  • Your JSON is not valid.

    Once you create a valid JSON string, parsing it is very simple.

    Use the following steps:

  • remove the commas after the last property of each object
  • remove the newlines
  • wrap the JSON text in single quotes
  • call jQuery.parseJSON() on the text
  • Here's a working fiddle.

    It does something like this:

    var jsonText = '[ { "cid": "3", "pid": "0", "nid"...} ]';
    var jo = $.parseJSON(jsonText);
    

    If you have the JSON in string form, you can use JSON.parse [MDN] to get it in object form, and then do with it what you need to.

    Modern browsers have this function natively - no jQuery necessary - but you can also include it yourself from one of these locations:

  • https://github.com/douglascrockford/JSON-js
  • https://code.google.com/p/json-sans-eval/
  • For a more complete list, see JSON.org.

    链接地址: http://www.djcxy.com/p/8492.html

    上一篇: 在javascript或jquery中解析Json

    下一篇: 我如何解析JQuery中的这个JSON对象?