Javascript phonegap+;jquerymobile+;JSON
如果我想将此json测试插入我的phonegap页面(其中包含jquery mobile),我会遇到一个问题:Javascript phonegap+;jquerymobile+;JSON,javascript,jquery,cordova,Javascript,Jquery,Cordova,如果我想将此json测试插入我的phonegap页面(其中包含jquery mobile),我会遇到一个问题: var JSONObject={“name”:“Amit”, “地址”:“B-123班加罗”, “年龄”:23岁, “电话”:“011-4565763”, “MobileNo”:0981100092 }; 文档。写入(“名称::” +JSONObject.name+“”); 文件。写(“地址:” +JSONObject.address+“”); 文件。写(“年龄::” +JSONObj
var JSONObject={“name”:“Amit”,
“地址”:“B-123班加罗”,
“年龄”:23岁,
“电话”:“011-4565763”,
“MobileNo”:0981100092
};
文档。写入(“名称::”
+JSONObject.name+“”);
文件。写(“地址:”
+JSONObject.address+“”);
文件。写(“年龄::”
+JSONObject.age+“”);
文件。填写(“电话号码:”
+JSONObject.phone+“”);
文件。写入(“手机号码:”
+JSONObject.MobileNo+“”);
那就不行了。。我的问题是,使用phonegap+jquery mobile是否真的可以使用JSON
将来我想要一个以JSON格式返回数据的Web服务,这样我就可以在我的phonegap应用程序中使用这个JSON数据。。我现在使用硬编码数据测试json数据是否有效。很可能在页面加载完成后调用此代码 因此,使用document.write没有任何意义 只需使用函数填充您想要填充的内容(可能是一个div) 请注意,必须等待DOM完全加载。最佳实践是使用onload事件处理程序,并将script元素放在正文的末尾
<div id=idOfTheDivWhereYouWantToWrite></div>
<script>
$(document).ready(function() {
var JSONObject = { "name" : "Amit",
"address" : "B-123 Bangalow",
"age" : 23,
"phone" : "011-4565763",
"MobileNo" : 0981100092
};
var html= "<h2><font color='blue'>Name</font>::"+JSONObject.name+"</h2>"
html += "<h2><font color='blue'>Address</font>::" +JSONObject.address+"</h2>";
html += "<h2><font color='blue'>Age</font>::" +JSONObject.age+"</h2>";
html += "<h2><font color='blue'>Phone No.</font>::"+JSONObject.phone+"</h2>";
html += "<h2><font color='blue'>Mobile No.</font>::"+JSONObject.MobileNo+"</h2>";
$('#idOfTheDivWhereYouWantToWrite').html(html);
});
</script>
$(文档).ready(函数(){
var JSONObject={“name”:“Amit”,
“地址”:“B-123班加罗”,
“年龄”:23岁,
“电话”:“011-4565763”,
“MobileNo”:0981100092
};
var html=“Name::”+JSONObject.Name+“”
html+=“地址::”+JSONObject.Address+”;
html+=“年龄::”+JSONObject.Age+”;
html+=“电话号码::”+JSONObject.Phone+”;
html+=“手机号码::”+JSONObject.MobileNo+”;
$('#idOfTheDivWhereYouWantToWrite').html(html);
});
此外,“JSON对象”并不意味着什么,因为JSON是一种交换格式。这只是一个普通的javascript对象。这不是JSON。JSON是一种语言,而不是javascript中的对象。@Esailija JSON是一种格式,而不是一种语言。@AurelioDeRosa它是一种语言。请不要把我和说“JSON是一种数据交换格式”的人联系起来。“这怎么就不是一种语言呢?”Esailija从维基百科开始?“Douglas Crockford是第一个指定并推广JSON格式的人”HTML是一种语言。XML是一种语言。JSON是。。。等等,什么?phonegap可以使用json吗?我正在使用phonegapYes开发一个ios应用程序,但你的问题中没有json。试着解释一下你想在问题中做什么。你有id为“idOfTheDivWhereYouWantToWrite”的div吗?没有,我做了,编辑:只是用div做了,但也没有结果我有多个页面,在phonegap中使用document.ready多个页面不是有问题吗?
<div id=idOfTheDivWhereYouWantToWrite></div>
<script>
$(document).ready(function() {
var JSONObject = { "name" : "Amit",
"address" : "B-123 Bangalow",
"age" : 23,
"phone" : "011-4565763",
"MobileNo" : 0981100092
};
var html= "<h2><font color='blue'>Name</font>::"+JSONObject.name+"</h2>"
html += "<h2><font color='blue'>Address</font>::" +JSONObject.address+"</h2>";
html += "<h2><font color='blue'>Age</font>::" +JSONObject.age+"</h2>";
html += "<h2><font color='blue'>Phone No.</font>::"+JSONObject.phone+"</h2>";
html += "<h2><font color='blue'>Mobile No.</font>::"+JSONObject.MobileNo+"</h2>";
$('#idOfTheDivWhereYouWantToWrite').html(html);
});
</script>