Can't access object property, even though it shows up in a console log

后端 未结 30 2100
日久生厌
日久生厌 2020-11-22 06:26

Below, you can see the output from these two logs. The first clearly shows the full object with the property I\'m trying to access, but on the very next line of code, I can\

30条回答
  •  春和景丽
    2020-11-22 07:13

    This might help somebody as I had a similar issue in which the JSON.parse() was returning an object that I could print on the console.log() but I couldn't acccess the specific fields and none of the above solution worked for me. Like using the combination of JSON.parse() with JSON.stringify().

    var jsonObj = JSON.parse(JSON.stringify(responseText))
    
    // where responseText is a JSON String returned by the server.
    
    console.log(jsonObj) ///Was printing the object correctly
    console.log(jsonObj.Body) /// Was printing Undefined  
    

    I ended up solving the problem by using a different parser provided by ExtJs Ext.decode();

    var jsonObj = Ext.decode(responseText)
    console.log(jsonObj.Body) //Worked...
    

提交回复
热议问题