JSON to string variable dump

前端 未结 5 1653
长发绾君心
长发绾君心 2020-12-02 10:15

Is there a quick function to convert JSON objects received via jQuery getJSON to a string variable dump (for tracing/debugging purposes)?

5条回答
  •  情书的邮戳
    2020-12-02 10:57

    i personally use the jquery dump plugin alot to dump objects, its a bit similar to php's print_r() function Basic usage:

    var obj = {
                hubba: "Some string...",
                bubba: 12.5,
                dubba: ["One", "Two", "Three"]
            }
    $("#dump").append($.dump(obj));
    /* will return:
    Object { 
         hubba: "Some string..."
         bubba: 12.5
         dubba: Array ( 
              0 => "One"
              1 => "Two"
              2 => "Three"
         )
    }
    */
    

    Its very human readable, i also recommend this site http://json.parser.online.fr/ for creating/parsing/reading json, because it has nice colors

提交回复
热议问题