javascript says JSON object property is undefined although it's not

后端 未结 4 574
抹茶落季
抹茶落季 2021-01-18 00:02

I have a json-object, which I print to the screen (using alert()-function):

alert(object);

Here is the result:

Then I want

4条回答
  •  别那么骄傲
    2021-01-18 00:34

    Your JSON is not parsed, so in order for JavaScript to be able to access it's values you should parse it first as in line 1:

    var result = JSON.parse(object);
    alert(result.id);
    

    After your JSON Objected is already parsed, then you can access it's values as following:

    alert(result.id);
    

提交回复
热议问题