
我正在尝试反序列化以下字符串,对于Java来说我是新手,我无法在我的一生中使用它…我现在仅尝试在对象中解码两个字符串.我的JSON和java类如下.我得到的结果变量确定.
{ "result": "true", "recentlyMarkedTerritorIEs": { "0": { "pk_activity": "471", "fk_activity_type": "100", "activity_content": "Hhhhh", "fk_user": "2", "activity_image": "2_QZe73f4t8s3R1317230457.jpg", "created": "1317244857", "activity_status": "1", "activity_location_lat": "43.515283", "activity_location_lon": "-79.880678", "fk_walk": null, "fk_event_location": "73", "user_point": "0", "public_image": "0", "fk_event_location_lat": "43.515273", "fk_event_location_lon": "-79.879989", "profile_image": "2_y9JlkI3CZDml1312492743.jpg", "user_gender": "1", "user_dob": "236073600", "user_nickname": "junoman", "isFrIEnd": "false", "profile_image_thumb": "2_y9JlkI3CZDml1312492743_t.jpg", "activity_image_thumb": "2_QZe73f4t8s3R1317230457_t.jpg", "relationship_status_IDx": "2", "isBlocked": "false" }, "1": { "pk_activity": "469", "fk_activity_type": "100", "activity_content": "JsJsJs", "fk_user": "1", "activity_image": null, "created": "1317244508", "activity_status": "1", "activity_location_lat": "43.515283", "activity_location_lon": "-79.880678", "fk_walk": null, "fk_event_location": "73", "user_point": "0", "public_image": "0", "fk_event_location_lat": "43.515273", "fk_event_location_lon": "-79.879989", "profile_image": "1_4Cpkofueqnrb1316895161.jpg", "user_gender": "1", "user_dob": "116841600", "user_nickname": "JoePennington", "isFrIEnd": "false", "profile_image_thumb": "1_4Cpkofueqnrb1316895161_t.jpg", "activity_image_thumb": null, "relationship_status_IDx": "1", "isBlocked": "false" }, ..... }}还有我下面的java类
RecentActivity infoList = null;Gson gson = new Gson();infoList = gson.fromJson(JsONString, RecentActivity.class);public class RecentActivity { String result; recentlyMarkedTerritorIEs recentlyMarkedTerritorIEs = null; public RecentActivity() { } public class recentlyMarkedTerritorIEs { public Set<recentlyMarkedTerritorIEs> pk_activity = new HashSet<recentlyMarkedTerritorIEs>() ; public recentlyMarkedTerritorIEs() { } }}请原谅我缺乏描述,但我确信代码会有所帮助. JsON已在其他应用程序中使用,因此不可更改.
谢谢!
解决方法:
这是一些不错的JsON教程,可以帮助您.
GSON
JSON
JSON Example with source code
更新
这样尝试
try { JsONObject object = new JsONObject(JsonString); JsONObject myObject = object.getJsONObject("recentlyMarkedTerritorIEs"); for (int i = 0; i < object.length(); i++) { JsONObject myObject2 = myObject.getJsONObject(Integer.toString(i)); System.out.println(myObject2.toString(2)); } } catch (Exception e) { e.printstacktrace(); } 总结 以上是内存溢出为你收集整理的JSON对象的Java表示全部内容,希望文章能够帮你解决JSON对象的Java表示所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)