如何从phonegap中的url下面获取json响应

时间:2013-05-17 12:57:49

标签: javascript android cordova jquery-mobile

任何人都可以帮我如何显示来自url的数据,我试过但我只获得一行数据。我发布了一次代码检查

http://www.apexweb.co.in/Apex_Quote/Phone_Gap/Download_Data.asp?un=9393910169


function check() {
var str1 = "http://www.apexweb.co.in/Apex_Quote/Phone_Gap/Download_Data.asp?un=9393910169";
        loadData(str1);
}
        // call service
    function loadData(URL_Str) {
    var head = document.getElementsByTagName('head')[0];
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = URL_Str;
        data = head.appendChild(script);
your_callback(data);
}
    // get response from service
    function your_callback(data) {
                var st1 = data.ContactName;
        var st2 = data.ContactNumber;
        var st3 = data.MainCategory;
        var st4 = data.SubCategory;

        alert(st1);
}

1 个答案:

答案 0 :(得分:0)

希望这有助于你

我在这里查看您的回复

开头 your_callback({"ContactName":"AksharmaDelhi","ContactNumber":"9313146690","MainCategory":"NONLOCAL","SubCategory":"LIG"},

结束
{"ContactName":"SAIDULU","ContactNumber":"9032364590","MainCategory":"LOCAL","SubCategory":"MIG"});

在开始到结束点响应时,需要将其响应更改为JSONArray,如({ )}[{ }],您可以获取所有数据

用于Json数据解析See Here

此外,您的回复错误有效Here 并且检查是否正确