我已经用JSON响应了WCF服务。我想从phonegap android上的JavaScript从WCF服务获取JSON字符串。但是,当我从JavaScript调用WCF服务时,来自WCF服务的响应为空。我已经测试过将此呼叫称为WCF服务,并且可以正常工作。我的JavaScript错误吗?
这是我的JavaScript:
<script type="text/javascript">
function displayText()
{
$.ajax(
{
type: "GET",
contentType: "application/json; charset=utf-8",
url: "http://10.80.3.73/webservice/Service1.svc/json/weeklyflash/id",
dataType: "json",
success:function(data){
alert(data);
},
error: function () {
alert("ERROR");
}
});
}
</script>
警报消息仅显示
[object Object]
,当我尝试使用Firebug进行跟踪时,响应为空。这是来自WCF服务的JSON字符串:
{"GetReportIdResult":[{"bulan":"4","total":"1728","type":"CHEESE1K","uang":"8796383"},{"bulan":"4","total":"572476","type":"ESL","uang":"5863408410"},{"bulan":"4","total":"46008","type":"ESL500ML","uang":"234498301"},{"bulan":"4","total":"190369","type":"UHT","uang":"1367063805"},{"bulan":"4","total":"33507","type":"WHP","uang":"235653242"},{"bulan":"5","total":"4761","type":"CHEESE1K","uang":"134877865"},{"bulan":"5","total":"648663","type":"ESL","uang":"6645764498"},{"bulan":"5","total":"49305","type":"ESL500ML","uang":"266817346"},{"bulan":"5","total":"245867","type":"UHT","uang":"1446787280"},{"bulan":"5","total":"47974","type":"WHP","uang":"631929807"},{"bulan":"6","total":"5762","type":"CHEESE1K","uang":"293393832"},{"bulan":"6","total":"594942","type":"ESL","uang":"6088671790"},{"bulan":"6","total":"39457","type":"ESL500ML","uang":"221983181"},{"bulan":"6","total":"236803","type":"UHT","uang":"2219506085"},{"bulan":"6","total":"24853","type":"WHP","uang":"386175022"}]}
最佳答案
当您使用jquery并指定dataType: 'json'
时,jQuery在调用成功回调之前会在运行时将json字符串反序列化为javascript对象。
您看到[object object]
的原因:这是字符串的表示形式
一个javascript对象。