Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.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
Java JSON解析:org.JSON.JSON.typeMismatch_Java_Android_Json - Fatal编程技术网

Java JSON解析:org.JSON.JSON.typeMismatch

Java JSON解析:org.JSON.JSON.typeMismatch,java,android,json,Java,Android,Json,我试图从URL解析JSON,我想我已经尝试了100种不同的方法,但到目前为止我还没有找到正确的解决方案。我相信我遇到的问题是来自JSON的数据结构。每个名称都以“0”开头,一直增加到最后一个。我想把所有这些公司都列入arraylist public static String url = "http://api.richmondsystemengineering.com/v1/?query_type=rva_card_get_businesses&appkey=51e53e510

我试图从URL解析JSON,我想我已经尝试了100种不同的方法,但到目前为止我还没有找到正确的解决方案。我相信我遇到的问题是来自JSON的数据结构。每个名称都以“0”开头,一直增加到最后一个。我想把所有这些公司都列入arraylist

    public static String url = "http://api.richmondsystemengineering.com/v1/?query_type=rva_card_get_businesses&appkey=51e53e510ecc14e4b2bde952f0c589f0";

    public static void getData(Context context) {
    // Hashmap for ListView

    ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();

    HttpClient httpClient = new DefaultHttpClient();
    HttpResponse response = null;
    HttpGet getMethod = new HttpGet(url);
    try {
        response = httpClient.execute(getMethod);

        // CONVERT RESPONSE TO STRING
        String result = EntityUtils.toString(response.getEntity());

        // CONVERT RESPONSE STRING TO JSON ARRAY
        JSONArray ja = new JSONArray(result);

        // ITERATE THROUGH AND RETRIEVE CLUB FIELDS
        int n = ja.length();
        for (int i = 0; i < n; i++) {
            // GET INDIVIDUAL JSON OBJECT FROM JSON ARRAY
            JSONObject c = ja.getJSONObject(i);
            Log.e("name", c.getString("phone"));


            // Storing each json item in variable
            companyName = c.getString("name");
            companyEmail = c.getString("email");
            companyAddress = c.getString("address");
            companyCity = c.getString("city");
            companyZip = c.getString("zip");
            companyDescription = c.getString("description");



            HashMap<String, String> map = new HashMap<String, String>();
            map.put("name", companyName);
            map.put("email", companyEmail);
            map.put("address", companyAddress);
            map.put("city", companyCity);
            map.put("zip", companyZip);
            map.put("description", companyDescription);
            contactList.add(map);


        }
    } catch (Exception e) {
        error = true;

        e.printStackTrace();
    }

}
关于Json: [{在这些括号中},{有一个数组},{对象数}] {在这些括号中是一个just-an-object}

你说“嘿,给我那个JSONArray”(天哪,它很押韵!),Eclipse告诉你:“你疯了吗?我没有看到数组”(隐藏的信息是只有一个对象,而不是数组)

更多关于json的信息


将响应转换为
JSONObject
而不是
JSONArray
,因为响应字符串包含
JSONObject
而不是
JSONArray
对不起,解析数据时有点慢。我该怎么做?请复制结果。Json结果非常大,但这里有一个链接。我把它放在Jsonlint.com中进行验证。
    org.json.JSONException: Value {"EAT_subcat":"farm, market and grocery","phone":"(804) 780-0086","WORK_subcat":"advertising","RID":"6","state":"","featured":"1","EAT":"1","city":"Richmond","DRINK":"1","distance":5532.3,"PLAY_subcat":"indoor and outdoor recreational activities","ENJOY_subcat":"entertainment and landmarks","updated":"2014-07-09 00:48:50","created":"2014-09-17 13:07:16","description":"Bistro 27 is a lively European bistro located in downtown Richmond, Virginia at the corner of Broad and Adams. With our floor-to-ceiling, wrap around windows and airy 20 foot ceilings, Twenty Seven offers a dining experience like no other in Richmond. Our menu is influenced by the hearty, healthy cuisines of Italy and France and features something for everyone's taste. Twenty Seven's wine lists ranges from inexpensive, little known gems to world class award winners. Parking is free at the corner of Adam and Grace Street, in the southwest corner. Look for the Bistro 27 sign  ","SHOP_subcat":"home garden goods and electronics","zip4":"0","name":"Bistro 27","longitude":"-77.442953","LIVE_subcat":"health fitness and edu classes","fname":"","zip":"23220","logo":"Pic"
at org.json.JSON.typeMismatch(JSON.java:100)
at org.json.JSONObject.getJSONArray(JSONObject.java:553)
at com.rse.rvacard.SearchActivity.getData(SearchActivity.java:167)
at com.rse.rvacard.SearchActivity.onCreate(SearchActivity.java:79)
at android.app.Activity.performCreate(Activity.java:5586)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2402)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2497)
at android.app.ActivityThread.access$900(ActivityThread.java:168)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1306)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5678)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
    // CONVERT RESPONSE TO STRING
    String result = EntityUtils.toString(response.getEntity());

    // CONVERT RESPONSE STRING TO JSON OBJECT
    JSONObject c = new JSONObject (result);

        // Storing each json item in variable
        companyName = c.getString("name");
        companyEmail = c.getString("email");
        companyAddress = c.getString("address");
        companyCity = c.getString("city");
        companyZip = c.getString("zip");
        companyDescription = c.getString("description");}