Gson使用方法之Tree Representation
来源:互联网 发布:泰拉瑞亚作弊软件 编辑:程序博客网 时间:2024/04/30 21:53
Tree prepresentation
利用JsonElement建立LinkedTreeMap来解析json,使用isJsonObject(),isJsonNull()等方法确定JsonElement的类型,利用getAsJsonObject(),getAsJsonPrimitive()等方法拿到对象
代码如下:
import java.io.IOException;import java.net.MalformedURLException;import java.net.URL;import org.apache.commons.io.IOUtils;import com.google.gson.JsonArray;import com.google.gson.JsonElement;import com.google.gson.JsonObject;import com.google.gson.JsonParser;public class ParseTokenTree {public static void main(String[] args) throws MalformedURLException, IOException {// TODO Auto-generated method stubString url = "http://freemusicarchive.org/api/get/albums.json?api_key=60BLHNQCAOUFPIBZ&limit=5";String json = IOUtils.toString(new URL(url));JsonParser parser = new JsonParser();JsonElement element = parser.parse(json);if (element.isJsonObject()) {JsonObject albums = element.getAsJsonObject();System.out.println(albums.get("title").getAsString());JsonArray datasets = albums.getAsJsonArray("dataset");for (int i = 0; i < datasets.size(); i++) {JsonObject dataset = datasets.get(i).getAsJsonObject();System.out.println("album title: " + dataset.get("album_title").getAsString());System.out.println("artist: " + dataset.get("artist_name").getAsString());}}}}
0 0
- Gson使用方法之Tree Representation
- Gson使用方法之Databinding
- Gson使用方法之streaming
- Gson使用方法之Serializing list
- Gson使用方法之Serializing Inner Classes
- Json序列化框架之Gson使用方法
- Gson使用方法
- Gson使用方法
- GSON使用方法
- GSON的使用方法
- Gson简单使用方法
- Gson的使用方法
- Google Gson的使用方法
- Gson的简单使用方法
- 【实训】Gson的使用方法
- Content Tree Word Embedding for document representation
- 【B-Human】之Module与Representation
- #DeepLearningBook#算法概览之八:Representation Learning
- 进程间数据通信方式和特点
- UIView animations with autolayout
- oralce 字段长度
- XBMC手持安卓媒体中心自己造
- iOS7导航栏遮盖问题的解决
- Gson使用方法之Tree Representation
- (leetcode) Best Time to Buy and Sell Stock II
- Linux下查看UUID方法以及修改
- 32位WINXP+VS2010编译vlc-1.1.5
- osg入门系列10-以索引方式的几何体绘制
- GState
- XBMC源代码分析 6:视频播放器(dvdplayer)-文件头(以ffmpeg为例)
- 从Java中访问native service的问题
- constvar: 一些图