Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.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
Php 为什么我能';在安卓系统中没有json?_Php_Android_Json - Fatal编程技术网

Php 为什么我能';在安卓系统中没有json?

Php 为什么我能';在安卓系统中没有json?,php,android,json,Php,Android,Json,我在获取一维JSON时遇到问题,请指导我问题出在我的JSON还是我的代码中 JSON: { "data": { "id": "S000010", "name": "ZS Solutions", "email": "zswebs@gmail.com", "phone": "051-1234567", "address": "p.o.box 123", "about": "im the compa

我在获取一维
JSON
时遇到问题,请指导我问题出在我的
JSON
还是我的代码中

JSON:

{
    "data": {
        "id": "S000010",
        "name": "ZS Solutions",
        "email": "zswebs@gmail.com",
        "phone": "051-1234567",
        "address": "p.o.box 123",
        "about": "im the company\r\nHAhahhaa"
    }
}
Android活动
JSON
检索代码:

ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
// TODO Auto-generated method stub
try {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("abc.php?Id="+id+"");

    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse hresponse = httpclient.execute(httppost);
    HttpEntity entity = hresponse.getEntity();
    is = entity.getContent();
    String result=co(is);
    JSONObject json=new JSONObject(result);

    JSONArray a=  json.getJSONArray(data);
    for (int i = 0; i <= a.length(); i++) {

        json = a.getJSONObject(i);
        String  cname=json.getString("name");
        String  cemail=json.getString("email");
        String  cphone=json.getString("phone");
        String  caddress=json.getString("address");
        String  cabout=json.getString("about");
        Log.w("DATA  ","NAME  "+cname+"E-mail  "+cemail+"Phone "+cphone+"ADDRESS"+caddress+"ABOUT"+cabout);
    }


}
catch(Exception e){}
ArrayList nameValuePairs=新的ArrayList();
//TODO自动生成的方法存根
试一试{
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost-HttpPost=newhttppost(“abc.php?Id=“+Id+”);
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
HttpResponse hresponse=httpclient.execute(httppost);
HttpEntity=hresponse.getEntity();
is=entity.getContent();
字符串结果=co(is);
JSONObject json=新的JSONObject(结果);
JSONArray a=json.getJSONArray(数据);

对于(int i=0;i
JSONArray a=json.getJSONArray(数据);
JSONArray a=json.getJSONArray(数据);
看起来数据是一个对象,而不是试图添加[]关于数据中的对象,请解释您正在尝试执行的操作以及哪些操作不起作用。如果出现异常或其他运行时错误,请添加logcat输出。看起来数据是一个对象,而不是试图添加[]的数组关于数据中的对象,请解释您正在尝试执行的操作和不起作用的操作。如果您有异常或其他运行时错误,请添加logcat输出。但“数据”中包含姓名、电子邮件、电话地址和关于如何取回这些文件?@Saad请检查上面的代码,您可以直接复制粘贴上面的文件,但仍然无法获取这些值..:(@Saad对于上面提到的JSONString,这是解析..log的方法来检查你的json是否返回vallue也检查是否有任何异常,如果有,请发布…@Saad Ok…当你获取json数据时,似乎有问题,所以试着识别它。如果你没有找到这方面的问题..这只回答了你当前的问题问题,即解析json。但是名称、电子邮件、电话地址和关于在“数据”中如何检索这些内容?@Saad请检查上述代码,您可以直接复制并粘贴上述内容,但仍无法获取这些值..:(@Saad对于上面提到的JSONString,这是解析..log的方法来检查你的json是否返回vallue也检查是否有任何异常,如果有,请发布…@Saad Ok…当你获取json数据时,似乎有问题,所以试着识别它。如果你没有找到这方面的问题..这只回答了你当前的问题问题,即解析json。
       JSONObject json=new JSONObject(result);

       JSONObject jsonobj=json.getJSONObject("data");

        String  cname=jsonobj.getString("name");
        String  cemail=jsonobj.getString("email");
        String  cphone=jsonobj.getString("phone");
        String  caddress=jsonobj.getString("address");
        String  cabout=jsonobj.getString("about");