0

私はjsonデータをリストビューにフェッチするアプリを作成していますが、jsonパーサーを使用してデータをリストビューに取得しながら、プログラムで$記号を価格に追加する方法がわかりません。ここにコードを配置しています:-

     @Override
          protected ArrayList<HashMap<String, String>> doInBackground(String... params) {
                  HttpClient client = new DefaultHttpClient();
                    // Perform a GET request to a JSON list of all the videos by a specific user
                    HttpUriRequest request = new HttpGet(URL);
                    // Get the response that sends back
                    HttpResponse response = null;
                    try {
                        response = client.execute(request);
                    } catch (ClientProtocolException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    // Convert this response into a readable string
                    String jsonString = null;
                    try {
jsonString = StreamUtils.convertToString(response.getEntity().getContent());
                    } catch (IllegalStateException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
    // Create a JSON object that we can use from the String
                    JSONObject json = null;
                    try {
                        json = new JSONObject(jsonString);
                    } catch (JSONException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }

                           try{

                 JSONArray jsonArray = json.getJSONArray(KEY_CATEGORY);

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

    HashMap<String, String> map = new HashMap<String, String>();
         JSONObject jsonObject = jsonArray.getJSONObject(i);                    

                        map.put("id",  String.valueOf(i));
map.put(KEY_TITLE, jsonObject.getString(KEY_TITLE));
map.put(KEY_DESCRIPTION, jsonObject.getString(KEY_DESCRIPTION));
map.put(KEY_COST, jsonObject.getString(KEY_COST));
map.put(KEY_THUMB_URL, jsonObject.getString(KEY_THUMB_URL));


                    itemsList.add(map);



                  } 
                    return itemsList;
            }catch(JSONException e)        {
                 Log.e("log_tag", "Error parsing data "+e.toString());
            }

                return null;

                }

JSON データ:-

{
"pizza":[
{
    "title" : "Pizza Item 1",
    "description" : "Lorem ipsum dolor sit amet, consectetur adipisicing elit",
    "cost" : "10.00",
    "imageUri" : "http://www.pizzahut.com.au/images/menu/Pizza-Lge-BBQ_Meatlovers.png"
},
{
    "title" : "Pizza Item 2",
    "description" : "Lorem ipsum dolor sit amet, consectetur adipisicing elit",
    "cost" : "9.00",
    "imageUri" : "http://www.pizzahut.com.au/images/menu/Pizza-Lge-BBQ_Meatlovers.png"
}

.........

4

1 に答える 1

0

マップ値に追加するだけで機能するはずです。

map.put(KEY_COST, jsonObject.getString(KEY_COST)+"$");
于 2012-10-27T10:59:44.297 に答える