您好 从2-3天开始,iam遇到了一个新问题,实际上我必须使用' api url'检索复杂的json数组,就像这样 -
{"response":{"success":true,"result":{"id":"45203511","device_id":"62970","message":"Rs. 20.00 refunded in your Paytm wallet for your order on Paytm. Updated balance:Rs. 20.0. Queries? Visit Paytm.com\/care.","status":"received","send_at":0,"queued_at":0,"sent_at":0,"delivered_at":0,"expires_at":0,"canceled_at":0,"failed_at":0,"received_at":1507375388,"error":"N\/A","created_at":1507375388,"contact":{"id":"9209301","name":"VK-IPAYTM","number":"VK-IPAYTM"}}},"status":200}
我想从这个json打印一个元素到控制台 " console.log(数据);" 这段代码在控制台中打印整个数组,但我只需打印" id"元件。 请帮帮我!!
答案 0 :(得分:1)
“我必须只打印”id“元素”
您的数据是嵌套对象,因此要获取任何对象属性,您可以执行object.property
或object["property"]
。这是一个例子,如何获得id
属性:
var obj = {"response":{"success":true,"result":{"id":"45203511","device_id":"62970","message":"Rs. 20.00 refunded in your Paytm wallet for your order on Paytm. Updated balance:Rs. 20.0. Queries? Visit Paytm.com/care.","status":"received","send_at":0,"queued_at":0,"sent_at":0,"delivered_at":0,"expires_at":0,"canceled_at":0,"failed_at":0,"received_at":1507375388,"error":"N/A","created_at":1507375388,"contact":{"id":"9209301","name":"VK-IPAYTM","number":"VK-IPAYTM"}}},"status":200}
console.log(obj.response.result.id)