[英]access to an array inside a object in javascript?
i have this code in (push notification payload) my application : 我在(推送通知有效负载)我的应用程序中有此代码:
var payload = {"message":"Bundle[{id=0, title=This is a test
notification, android.support.content.wakelockid=3,
collapse_key=push, from=93469011985}]","inBackground":0};
And i want to access to the "id" and "title" properties in this JSON. 我想访问此JSON中的“ id”和“ title”属性。 How can i do this ? 我怎样才能做到这一点 ? thx in advance :) 提前谢谢:)
I have tried to do things like this : 我试图做这样的事情:
console.log (payload.message['id'])
But it does not work. 但这行不通。
var id = payload.message.substring(payload.message.indexOf("id=") + 3, payload.message.indexOf(",", payload.message.indexOf("id=")));
var title = payload.message.substring(payload.message.indexOf("title=") + 6, payload.message.indexOf(",", payload.message.indexOf("title=")));
console.log(id, title);//prints 0 This is a test notification
Warning This code will fail if you have ,
in the middle of the title. 警告如果标题中间有,
则此代码将失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.