Konvertieren von JSON-Schlüssel-Wert-Paare in JSON-Array Android

Ich habe ein array von Schlüssel-Wert-Paare wie dieses:

{
  "320x240":"http:\/\/static.example.com\/media\/content\/2012\/Jul\/mercedes-benz-a-klasse-red-t_320x240.jpg",
  "300x225":"http:\/\/static.zigwheels.com\/media\/content\/2012\/Jul\/mercedes-benz-a-klasse-red-t_300x225.jpg",
  "200x150":"http:\/\/static.zigwheels.com\/media\/content\/2012\/Jul\/mercedes-benz-a-klasse-red-t_200x150.jpg"
}

Was ich mache zurzeit ist diese:

   try {

      images_object = new JSONObject(imageList);//imageList is a String of the above array //of key value pairs

            Iterator<?> keys = images_object.keys();
            String string_images = "";
           if(keys.hasNext()) {
               String key = (String)keys.next();
                String value = (String)images_object.get(key);
                string_images = "[" + value;  
           }
            while( keys.hasNext() ){
                String key = (String)keys.next();
                String value = (String)images_object.get(key);
                string_images = string_images + "," + value;

            }
            string_images = string_images + "]";
            String encoded_json_string = JSONObject.quote(string_images);
            images = new JSONArray(encoded_json_string);//images is of type JSONArray but it is null
        } catch (JSONException e) {
            //TODO Auto-generated catch block
            e.printStackTrace();
        }

Aber, die Bilder, die NULL ist. Warum? Was bin ich?

  • Da bist du nicht der Erstellung gültigen JSON. string_images wird in keiner Weise ähneln gültige JSON, die erfordert Streicher zitiert zu werden.
  • Könnten Sie mir sagen, was falsch ist? Ich habe auch versucht haben, entfernen die eckigen Klammern.
  • Was ist dein problem mit der unten beantworten? Hast du das ausprobiert?
InformationsquelleAutor Namratha | 2013-05-09
Schreibe einen Kommentar