我有一个JSON对象如何解析JSON对象的字符串
{
"data": [{
"user_id":"1",
"user_name":"test",
"user_phone":"2147483647",
"user_email":"[email protected]"
}]
}
和jQuery的循环功能
$.each(responseData, function(index, ProfileData) {
profiles.push(
application.getModel("Profile", [ ProfileData.user_id, ProfileData.user_name, ProfileData.user_phone, ProfileData.user_email ])
);
});
但当JSON对象成为这个
{
"data": [{
"firm_id":"1",
"firm_name":"Firm",
"firm_phone":"2147483647",
"firm_email":"[email protected]"
}]
}
然后我想检查JSON数据是否有user
或firm
扩展名,也需要我们e代替push()
。
application.getModel("Profile", [ ProfileData.user_id, ProfileData.user_name, ProfileData.user_phone, ProfileData.user_email ])
这是一个很好的答案,但关于您的评论,JavaScript对象的JavaScript数组= = JSON。 – graphicdivine 2011-12-14 10:24:08
JSON通常意味着“JavaScript Object Notation”...它涵盖了Javascript内部的对象文字符号和此对象的字符串表示形式(例如,使用JSON.stringify()) – devnull69 2011-12-14 10:25:07
谢谢David解决方案 – user1066679 2011-12-14 10:29:17