java - How to use Jackson to deserialise Array Like This? -
how deserialise simple? json like:
{ "ok": 1, "data": { "a": [ { "brand": "aman", "logo": "http://zxmall.bluedoor.com.cn/uploads/logo/61.png" } ], "b": [ { "brand": "base-ds", "logo": "http://zxmall.bluedoor.com.cn/uploads/logo/24.png" }, { "brand": "bb", "logo": "http://zxmall.bluedoor.com.cn/uploads/logo/46.png" }, { "brand": "banane", "logo": "http://zxmall.bluedoor.com.cn/uploads/logo/11.png" } ], "c": [ { "brand": "cat", "logo": "http://zxmall.bluedoor.com.cn/uploads/logo/78.png" }, { "brand": "car", "logo": "http://zxmall.bluedoor.com.cn/uploads/logo/129.png" } ] } }
from [a-z].
my code below:
reslutmod data = jsonutil.jsontomod(json, reslutmod.class);
in jsonutil:
public static <t> t jsontomod(string jsonstring, class<t> clazz) { if (stringutils.isempty(jsonstring)) { return null; } try { return jsonmapper .getinstance() .getjsonmapper().readvalue(jsonstring, clazz); } catch (ioexception e) { e.printstacktrace(); return null; } }
javabean:
public class reslutmod { public int ok; public brandlistmod data; }
javabean2:
public class brandlistmod { public arraylist<cardbrandmodel> a; public arraylist<cardbrandmodel> b; public arraylist<cardbrandmodel> c; public arraylist<cardbrandmodel> d; public arraylist<cardbrandmodel> e; public arraylist<cardbrandmodel> f; public arraylist<cardbrandmodel> g; public arraylist<cardbrandmodel> h; public arraylist<cardbrandmodel> i; public arraylist<cardbrandmodel> j; public arraylist<cardbrandmodel> k; public arraylist<cardbrandmodel> l; public arraylist<cardbrandmodel> m; public arraylist<cardbrandmodel> n; public arraylist<cardbrandmodel> o; public arraylist<cardbrandmodel> p; public arraylist<cardbrandmodel> q; public arraylist<cardbrandmodel> r; public arraylist<cardbrandmodel> s; public arraylist<cardbrandmodel> t; public arraylist<cardbrandmodel> u; public arraylist<cardbrandmodel> v; public arraylist<cardbrandmodel> w; public arraylist<cardbrandmodel> x; public arraylist<cardbrandmodel> y; public arraylist<cardbrandmodel> z; }
i don't think way. can do?
you can use map here.
e. g. :
class reslutmod { public int ok; public map<string, arraylist<cardbrandmodel>> data; public int getok() { return ok; } public void setok(int ok) { this.ok = ok; } public map<string, arraylist<cardbrandmodel>> getdata() { return data; } public void setdata(map<string, arraylist<cardbrandmodel>> data) { this.data = data; } }
where class cardbrandmodel :
class cardbrandmodel { string brand; string logo; public string getbrand() { return brand; } public void setbrand(string brand) { this.brand = brand; } public string getlogo() { return logo; } public void setlogo(string logo) { this.logo = logo; } }
Comments
Post a Comment