Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JSON字符串通过AJAX与jquery、Android_Jquery_Android_Ajax_Json_Cordova - Fatal编程技术网

JSON字符串通过AJAX与jquery、Android

JSON字符串通过AJAX与jquery、Android,jquery,android,ajax,json,cordova,Jquery,Android,Ajax,Json,Cordova,我一直在用phonegap开发android应用程序。有人能帮助我如何调用我的Web服务,通过AJAX和jquery通过android应用程序输出JSON字符串吗?非常感谢你的帮助 我的Jscript中有以下代码: $(document).bind("mobileinit", function(){ $.support.cors = true; $.mobile.allowCrossDomainPages = true; }); $.ajax({ type: "POST", timeo

我一直在用phonegap开发android应用程序。有人能帮助我如何调用我的Web服务,通过AJAX和jquery通过android应用程序输出JSON字符串吗?非常感谢你的帮助

我的Jscript中有以下代码:

$(document).bind("mobileinit", function(){
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
});

$.ajax({
  type: "POST",
  timeout: moneTimeout,
  url: "http://10.0.2.2:49878/SampleProject.aspx?p_trxn_type=doLogin&p_phoneNumber="+phoneNumber,
  error: function (xhr, status, errorThrown)
  { 
   alert(xhr.status);
  },
  dataType : "json",
  cache:false,
  async:false,
  success: function (ret)
  {
   try{
    var jsonObj = eval('(' + ret + ')');
    alert(jsonObj.Contacts.Contact['@phoneNumber']);
    alert(jsonObj.Contacts.Contact.LastName);
    alert(ret.Contacts.Contact['@phoneNumber'])
    alert(ret.Contacts.Contact.LastName);
   }
   catch(ex){
    alert(ex.message);
   }
   console.log(ret);
   alert(ret.length);
   alert(ret);
   alert(typeof ret);
   alert("success");
  }
 });
这是我想从我的c#webservice获得的JSON数组:

    {"Contacts":{"Contact":{"@phoneNumber":"0002221111","@countryCode":"1","@typeCode":"73","@type":"Default, Mobile, DefaultContactNumber","@id":"04359c0dcca64638a5fcbb17b386ceed","Salutation":"Mr.","FirstName":"Tom","MiddleName":null,"LastName":"Cruise","NameSuffix":null,"PrimaryAddress":{"Street":{"#cdata-section":"3135 Teodoro Drive"},"Street2":{"#cdata-section":""},"City":{"#cdata-section":"Detroit"},"State":"MS","Country":"US","Postal":"48228"}}}

我仍然收到一个警报:error,如果您正在查找特定于jquery的代码,它不会显示我的c#webservice中的JSON字符串数组。也许这会有帮助

$.getJSON("http://yoururl.com?jsoncallback=?",  {
       requestParam: "someValue",  },  function(data) {
        //handle data  
       }
    );

有关更多信息,您可以查看:

对于我来说,我正在使用EclipseHelio在Android上进行phonegap开发。我正在为以下内容编写代码:(使用Youtube API和JSONC格式)

编辑器抱怨“default”是意外的标记。起初,我忽略了它。它可以编译并在我的HTC vivid上运行。 然而,当我在我的其他设备(Galaxy Tab 2.2、Galaxy S2.3.4)上测试它时,它们都无法工作。它们都有“文件中的意外令牌默认值…”错误 因此,我将代码更改为使用YouTube API JSON格式。现在我所有的设备都能正常工作了。只是JSON格式包含的数据比我需要的要多,我正试图使带宽使用率尽可能低。
底线是,我想JS会抱怨变量的名称与oprand相同。

你愿意使用任何PhoneGap特定的方法还是只播放jQuery ajax例程?最好从这里开始@Jasper:我已经编辑了我的问题并添加了jscript中的代码。@Moss:如果你能给我一个示例或我可以提供的参考资料的话依靠那么,为什么不呢?@新手试试这个:
var myJsondoc = JSON.parse(data.text);
var writeintoHTML = document.getElementById('the_list');
writeintoHTML += myJsondoc.data.items[0].player.default;