-1

大きなJsonファイルの解析に助けが必要です:

{"status":{"code":200,"text":"OK"},"content":[{"proposalId":"12536","providerId":"1","supervisorName":null,"supervisorEmail":"lolbroek_13@hotmail.com","hostInstitution":"qsd","hostCountry":"qsd","hostCity":"QSD","hostTypeId":"1","title":"qsd","status":"available","numberStudents":null,"description":"qsd","categoryId":"34","startDate":null,"endDate":null,"submitDate":null,"expectedWorkload":null,"purpose":null,"workOrganisationId":"1","function":null,"audienceId":"1","preConditions":"","certificationGranted":null,"deliverables":null,"expenses":null,"revenue":null,"vacancies":null,"uploadImg":"http:\/\/193.136.60.238\/\/MUTW2012\/core\/img\/internship.png"},
{"proposalId":"12537","providerId":"1","supervisorName":null,"supervisorEmail":"lolbroek_13@hotmail.com","hostInstitution":"qsd","hostCountry":"qsd","hostCity":"QSD","hostTypeId":"1","title":"qsd","status":"available","numberStudents":null,"description":"qsd","categoryId":"34","startDate":null,"endDate":null,"submitDate":null,"expectedWorkload":null,"purpose":null,"workOrganisationId":"1","function":null,"audienceId":"1","preConditions":"","certificationGranted":null,"deliverables":null,"expenses":null,"revenue":null,"vacancies":null,"uploadImg":"http:\/\/193.136.60.238\/\/MUTW2012\/core\/img\/internship.png"},
{"proposalId":"12538","providerId":"1","supervisorName":null,"supervisorEmail":"lolbroek_13@hotmail.com","hostInstitution":"qsd","hostCountry":"qsd","hostCity":"QSD","hostTypeId":"1","title":"qsd","status":"available","numberStudents":null,"description":"qsd","categoryId":"34","startDate":null,"endDate":null,"submitDate":null,"expectedWorkload":null,"purpose":null,"workOrganisationId":"1","function":null,"audienceId":"1","preConditions":"","certificationGranted":null,"deliverables":null,"expenses":null,"revenue":null,"vacancies":null,"uploadImg":"http:\/\/193.136.60.238\/\/MUTW2012\/core\/img\/internship.png"},
{"proposalId":"12539","providerId":"1","supervisorName":null,"supervisorEmail":"lolbroek_13@hotmail.com","hostInstitution":"qsd","hostCountry":"qsd","hostCity":"QSD","hostTypeId":"1","title":"qsd","status":"available","numberStudents":null,"description":"qsd","categoryId":"34","startDate":null,"endDate":null,"submitDate":null,"expectedWorkload":null,"purpose":null,"workOrganisationId":"1","function":null,"audienceId":"1","preConditions":"","certificationGranted":null,"deliverables":null,"expenses":null,"revenue":null,"vacancies":null,"uploadImg":"http:\/\/193.136.60.238\/\/MUTW2012\/core\/img\/internship.png"},
................[etc]

コンテンツ内のすべてのタイトルとプロポーザル ID を取得する必要があります。私はそれを次のようにしようとしました:

public ArrayList<String> GetUserProposals(String UserId){
        String actionname = sitename+"accounts/"+UserId+"/proposals";
        try {
           jObject = this.sendData(actionname);//change later
          // return result;
           JSONArray ja = jObject.getJSONArray("content");
           for (int i = 0; i < ja.length(); i++) {
                Log.i("MyDebug", "value----" + ja.getJSONObject(i).getString("title"));
           }
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        ArrayList<String> returnValue = null;
        return returnValue;

    }

しかしJSONArray、空です。

4

3 に答える 3

0

これはあなたに役立ちます..JSONを解析している間、json配列[]とjsonオブジェクト{}があります

   DefaultHttpClient httpclient = new DefaultHttpClient(
            new BasicHttpParams());
    HttpPost httppost = new HttpPost(
            "Your Json URL");

    httppost.setHeader("Content-type", "application/json");

    InputStream inputStream = null;
    String result = null;
    HttpResponse response = null;
    try {
        response = httpclient.execute(httppost);

        HttpEntity entity = response.getEntity();

        inputStream = entity.getContent();
        BufferedReader reader = null;

        reader = new BufferedReader(new InputStreamReader(inputStream,
                "UTF-8"), 8);

        StringBuilder sb = new StringBuilder();

        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        result = sb.toString();
        int k = 0;

        JSONObject jObject = null;

        jObject = new JSONObject(result);

        String aJsonString = jObject.getString("results");
        String name = aJsonString;

        JSONArray jArray = null;

        jArray = jObject.getJSONArray("results");

        JSONObject oneObject = null;
        oneObject = jArray.getJSONObject(0);

        JSONArray jArray1 = null;
        jArray1 = oneObject.getJSONArray("address_components");//keyword

        JSONObject oneObject1 = null;
        oneObject1 = jArray1.getJSONObject(1);

        String oneObjectsItem1 = oneObject1.getString("long_name");//keyword
        City = oneObjectsItem1;

    }

    catch (IOException e) {
        int x = 0;
    }
    return City;
于 2012-06-13T09:02:26.430 に答える
0

jObject = this.sendData(actionname);「jObject = new JSONObject(this.sendData(actionname));」に切り替えてみてください。

JSONオブジェクトを初期化する必要がありますが、そうではありません...

于 2012-06-13T08:27:44.597 に答える
0

私のJSON文字列は

{
"result": "success",
"countryCodeList": [
{
"countryName": "World Wide",
"countryCode": "00"
},
{
"countryName": "Korea, Republic of",
"countryCode": "kr"
},
{
"countryName": "United States",
"countryCode": "us"
},
{
"countryName": "Japan",
"countryCode": "jp"
},
{
"countryName": "China",
"countryCode": "cn"
},
{
"countryName": "India",
"countryCode": "in"
}
]
}

そして、私はこのように解析しました

        JSONObject json = new JSONObject(jsonstring);

        status = json.getString("result");

        if (status.equalsIgnoreCase("success")) {


            JSONArray nameArray = json.names();
            JSONArray valArray = json.toJSONArray(nameArray);

            JSONArray valArray1 = valArray.getJSONArray(1);

            valArray1.toString().replace("[", "");
            valArray1.toString().replace("]", "");

            int len = valArray1.length();

            for (int i = 0; i < valArray1.length(); i++) {

                Country country = new Country();
                JSONObject arr = valArray1.getJSONObject(i);

                country.setCountryCode(arr.getString("countryCode"));
                country.setCountryName(arr.getString("countryName"));
                arrCountries.add(country);
            }
        }
于 2012-06-13T08:37:49.337 に答える