我有一個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