我裏面的值用JSON一個Map.Entry,我想使這個值到地圖我如何循環(爲/,而/循環)對一個Map.Entry
隨着例子它會更容易解釋: 我做的API請求這樣的URL:
response1 = httpclient.execute(httpGet);
這是我的JSON從請求得到:
{"Projects":
[{"Role":"ProjectAdmin","Url":"http://**/","OverSized":false,"Folders":
[{"Name":"sh","Url":"http://**/","Permssion":"rw"}]},
{"Role":"ProjectAdmin","Url":"http://**/Goooood","OverSized":false,"Folders":
[{"Name":"Goooood","Url":"http://**/Goooood","Permssion":"rw"}]}],
"DeviceToken":"token",
"TotalProjects":2}
這是怎麼餘噸將JSON轉換成MAP:
ContainerFactory containerFactory = new ContainerFactory()
{
public List creatArrayContainer() {return new LinkedList();}
public Map createObjectContainer() {return new LinkedHashMap();}
};
BufferedReader br = new BufferedReader(new InputStreamReader(response1.getEntity().getContent()));
StringBuilder content = new StringBuilder();
String line;
//TODO:Remove and build a better JSON parser
while (null != (line = br.readLine()))
{
content.append(line);
}
JSONParser parser = new JSONParser();
try
{
json = (Map)parser.parse(content.toString(), containerFactory);
Iterator iter = json.entrySet().iterator();
}
現在一切都很好! 現在我可以iter
這樣做了一段時間:
while(iter.hasNext())
{
Map.Entry entry = (Map.Entry)iter.next();
System.out.println(entry.getKey() + "=>" + entry.getValue());
}
我現在的問題是,我有一個entry.getValue()
有JSON在裏面。
例子:
[{"Role":"ProjectAdmin","Url":"http://**/","OverSized":false,"Folders":
[{"Name":"sh","Url":"http://**/","Permssion":"rw"}]},
{"Role":"ProjectAdmin","Url":"http://**/Goooood","OverSized":false,"Folders":
[{"Name":"Goooood","Url":"http://**/Goooood","Permssion":"rw"}]}]
,我需要從中做出地圖像我從反應都能夠循環播放。 有沒有辦法做到這一點? 有沒有辦法做到這一點?
我不認爲這是一個問題,使它成爲一個字符串reMap,就像我在開始時所做的一樣,但我有一種感覺,有一個更好的方法。
謝謝!
你怎麼知道它是一個json而不是一個普通的字符串值?按鍵?也許這有助於:http://json.org/java/ – Fildor 2013-05-09 11:01:36
是的。這是我的api服務器 – Ofear 2013-05-09 11:03:03