gpt4 book ai didi

java - 如何在Android中过滤JsonObject中的值?

转载 作者:行者123 更新时间:2023-12-02 12:37:55 25 4
gpt4 key购买 nike

> {"-Kopv2EYUt7EeisRiiCz":{"deviceName":"LYF","fileUploadDate":"07\/12\/2017 2:00:57 PM"},
"-KopvA-cTtzgzSbsKTrw":{"deviceName":"LYF","fileUploadDate":"07\/12\/2017 2:01:29 PM",}}

如何解析 JsonObject 中的所有“fileUploadDates”?

fileUploadDate = 07\/12\/2017 2:00:57 PM
fileUploadDate = "07\/12\/2017 2:01:29 PM

最佳答案

使用GSON库

public void parseJson(String json){
Gson gson = new Gson();
Type stringStringMap = new TypeToken<Map<String, Map<String,String>>>(){}.getType();
Map<String,Map<String,String>> map = gson.fromJson(json, stringStringMap);

Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
Map<String,String> innerMap = (Map<String,String>)pair.getValue();
getInnerMapDetail(innerMap);
it.remove(); // avoids a ConcurrentModificationException
}
}
public void getInnerMapDetail(Map<String,String> innerMap)
{
String fileUploadDate = innerMap.get("fileUploadDate"); // you will get here
}

}

关于java - 如何在Android中过滤JsonObject中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45077805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com