android - Json to string array using Gson -



android - Json to string array using Gson -

i'm having troubles deserialization of json:

[{"categorium": {"created_at":"2011-06-09t08:57:41z","c1":"rete stradale","updated_at":"2011-06-09t08:57:41z","id":1}}, {"categorium":{"created_at":"2011-06-09t13:50:29z","c1":"servizi pubblici","updated_at":"2011-06-09t13:50:29z","id":2}}, {"categorium":{"created_at":"2011-06-09t13:50:37z","c1":"illuminazione","updated_at":"2011-06-09t13:50:37z","id":3}}, {"categorium":{"created_at":"2011-06-09t13:50:46z","c1":"inquinamento","updated_at":"2011-06-09t13:50:46z","id":4}} ]

how can extrapolate "c1" attributes, can homecoming string array of them?

*update: solution *

public class getelements { string [] getel (string url) throws clientprotocolexception, ioexception { categoria c = null; categoria[] carray = null; string [] c1array = null; httpclient client = new defaulthttpclient(); httpget request = new httpget("http://10.0.2.2:3000/"+url); httpresponse response = client.execute(request); httpentity entity = response.getentity(); string stringa = "{\"categorium\":{\"created_at\":\"2011-06-09t08:57:41z\",\"c1\":\"rete stradale\",\"updated_at\":\"2011-06-09t08:57:41z\",\"id\":1}}"; gson json=new gson(); try{ carray=json.fromjson(stringa, categoria[].class); log.i("elemento", ""+carray); }catch(jsonparseexception e){ log.i("error","jsonparseexception"); } c1array = new string[carray.length]; (int i=0; i<carray.length; i++) { c1array[i] = carray[i].c1; } homecoming c1array; } }

categorium class:

public class categoria { public string created_at; public string c1; public string updated_at; public int id; public categoria() { this.created_at = ""; this.c1=""; this.updated_at = ""; this.id = 0; } }

to deserialize array utilize code:

categorium[] carray = null; carray = gson.fromjson(stringa, categorium[].class);

then c1's:

string[] c1array = new string[carray.length]; (int i=0; i<carray.length; i++) { c1array[i] = carray[i].c1; }

android json gson

Comments

Popular posts from this blog

groovy - Grails 2.0 plans for arbitrary .gsp pipelining? -

linux - Why do the 32-bit and 64-bit Compiled Versions of this Program Populate Memory in this Way? -

c# - Code indenting specified at project/solution level rather than global -