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

后端 未结 4 686
抹茶落季
抹茶落季 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:49

    In JavaScript, object properties can be accessed with . operator or with associative array indexing using []. I.e. object.property is equivalent to object["property"]

    You can try:

    var obj = JSON.parse(Object);
    alert(obj.id); 
    

提交回复
热议问题