本帖最后由 menghuanchiyue 于 2014-01-15 16:53:50 编辑

解决方案 »

  1.   

    var json=jQuery.parseJSON("{\"a\":\"123\"}")alert(json.a);
      

  2.   

    我是想知道parseJSON这个函数的实现方法,就是具体代码
      

  3.   


    C#有现成的工具
    Newtonsoft.Json
    LitJson
      

  4.   

    我知道c#有工具,我是要学习parseJSON的实现方法
      

  5.   

    js
        var func = new Function("return {\"a\":\"123\"}");
        var str = func();
        alert(str.a);
      

  6.   


    parseJSON: function( data ) {
    // Attempt to parse using the native JSON parser first
    if ( window.JSON && window.JSON.parse ) {
    return window.JSON.parse( data );
    } if ( data === null ) {
    return data;
    } if ( typeof data === "string" ) { // Make sure leading/trailing whitespace is removed (IE can't handle it)
    data = jQuery.trim( data ); if ( data ) {
    // Make sure the incoming data is actual JSON
    // Logic borrowed from http://json.org/json2.js
    if ( rvalidchars.test( data.replace( rvalidescape, "@" )
    .replace( rvalidtokens, "]" )
    .replace( rvalidbraces, "")) ) { return ( new Function( "return " + data ) )();
    }
    }
    } jQuery.error( "Invalid JSON: " + data );
    },
      

  7.   

    可能我表达有问题吧,我是想学习parseJSON函数,
    用直接用JS实现,楼上的代码没法学习,只是部分的实现代码而已
      

  8.   


    给你一个发动机去组装汽车,你还要去了解发动机的每个配件?new Function()就是js里面的一个内部方法,如果要问他是什么,那只能去了解浏览器,然后是整个二进制的编译过程
      

  9.   

    我觉得楼主应该先学会用google,这是搜索的第一项结果:
    http://api.jquery.com/jquery.parsejson/
      

  10.   

    楼主可以在使用浏览器调试的时候 在console里面输入jQuery.parseJSON 就可以看到对应的完善parseJSON方法了。
    楼主还可以找到JQuery .all 的文件查找parseJSON这个方法