我是java/Android的初学者,我尝试使用Gson解析JSON。Gson with dynamic name(Android)
我在文件部分有一些困难。 从我读过,我应该使用MapHash,但我不知道如何在这段代码
这里我主要的类使用它
InputStream source = retrieveStream(url);
Gson gson = new Gson();
Reader reader = new InputStreamReader(source);
SearchResponse response = gson.fromJson(reader, SearchResponse.class);
是做解析类
public class SearchResponse {
public List<Podcast> podcasts;
class Podcast {
@SerializedName("files")
private List<File> files;
@SerializedName("format")
private String format;
@SerializedName("title")
private String title;
class File {
private String ValueX;
private String URLX;
}
}
}
JSON结构
{
"podcasts": [
{
"files": [
{"NameA": "ValueA"},
{"NameB": "ValueB"},
{"...": "..."}
],
"format": "STRING",
"title": "STRING"
}
]
}
感谢您的帮助
这里的JSON的结构的编辑过的文件我尝试解析 http://jsontest.web44.net/noauth.json
您可以解析JSON即使不使用GSON。你想从JSONObject中获得什么? –
我想获得名称和值。 – Keven
Yourere有你的JSON对象,这可能是来自某个地方的回应? –