如何迭代String,String的地图集合。迭代java中的地图集合
我有一个POJO类
public class GPObject_PublicUser {
private String kind;
private String id;
private String displayName;
private String objectType;
private String gender;
private String aboutMe;
private String url;
private Map<String,String> image;
private Collection<Map<String,String>> placesLived;
}
现在我转换字符串GSON并尝试将数据映射到POJO类。
Gson gson = new Gson();
GPObject_PublicUser hello =gson.fromJson(jsonText, GPObject_PublicUser.class);
样品JSON文本:
{ "kind": "plus#person", "etag": "\"goGJzLGpDAdTIjyZUs7et8jwqfg/dSQkZzjp1Ufk7Fq69sg0cCLCwLY\"", "occupation": "Global News Broadcaster", "gender": "other", "urls": [ { "value": "http://twitter.com/cctv_america", "type": "otherProfile", "label": "CCTV_America" }, { "value": "https://www.facebook.com/CCTVAmerica", "type": "otherProfile", "label": "Facebook" }, { "value": "http://www.cctv-america.com", "type": "contributor", "label": "CCTV-America.com" }, { "value": "http://www.cctv-america.com", "type": "other", "label": "Official Website" } ], "objectType": "person", "id": "105608978310637089588", "displayName": "CCTV America", "name": { "familyName": "America", "givenName": "CCTV" }, "tagline": "CCTV America contributes programming from Washington DC to CCTV News, the 24-hour English-language news channel of China Central Television", "aboutMe": "\u003cdiv\u003eCCTV America launched from Washington on Monday, February 6th 2012.  It currently produces five hours of weekday programming seen on the North American east coast in the early evening hours.  Programs include numerous daily news broadcasts as well as BIZ ASIA AMERICA, focusing on global economic trends, trade and investment.\u003c/div\u003e\u003cdiv\u003e“The Heat,� weekdays at 7pm EST provides talk-and-debate on a range of topical issues. 'Americas Now' on Sunday nights provides in depth magazine coverage on Central and South American issues.  It is the only regularly scheduled magazine program in the English language exploring Latin American issues.\u003c/div\u003e\u003cdiv\u003e\u003cbr /\u003e\u003c/div\u003e\u003cdiv\u003eCCTV America programming can be seen from 3pm EST\u003c/div\u003e\u003cdiv\u003eCOMCAST Channel 273, FIOS 277 in the greater Washington area.\u003c/div\u003e\u003cdiv\u003eIn New York watch Time Warner Channel 134.\u003c/div\u003e\u003cdiv\u003eIn Los Angeles watch Charter Cable Channel 562.\u003c/div\u003e\u003cdiv\u003eNationwide watch DISH TV channel 279.\u003c/div\u003e\u003cdiv\u003eCheck your cable TV listings for availability in different US locations.\u003c/div\u003e\u003cdiv\u003eExcerpts of all programming can be seen on \u003ca href=\"http://www.cctv-america.com\" rel=\"nofollow\" target=\"_blank\"\u003ewww.cctv-america.com\u003c/a\u003e.\u003c/div\u003e\u003cdiv\u003e\u003cbr /\u003e\u003c/div\u003e", "url": "https://plus.google.com/105608978310637089588", "image": { "url": "https://lh4.googleusercontent.com/-xiA6h0u4IO8/AAAAAAAAAAI/AAAAAAAAAMQ/Hv4BxXfO-_Q/photo.jpg?sz=50", "isDefault": false }, "organizations": [ { "name": "CCTV America", "type": "work", "startDate": "2012", "primary": true } ], "placesLived": [ { "value": "Washington, D.C., DC 20002, United States", "primary": true } ], "isPlusUser": true, "circledByCount": 101, "verified": false, "cover": { "layout": "banner", "coverPhoto": { "url": "https://lh3.googleusercontent.com/-c5Kov6t3y2o/U2KUhNrAClI/AAAAAAAAAME/RZEIUxBcMnk/s630-fcrop64=1,3ceb2465cd58ffff/facebook_banner.png", "height": 347, "width": 940 }, "coverInfo": { "topImageOffset": 0, "leftImageOffset": 0 } }}
现在我的问题是我怎么能遍历的placeLived来获取值。
参见http://stackoverflow.com/questions/46898/how-do-i -ite-over-each-entry-in-a-map – Raedwald
我认为,即使粗略阅读Java引用,这也应该是显而易见的。这真的值得SO贴吗? – balajeerc
另请参阅http://stackoverflow.com/questions/20654289/iterate-through-collectionlistinteger – Raedwald