Json解析之JsonArray 附加Gson生成与解析 对象解析json
来源:互联网 发布:人工智能技术培训材料 编辑:程序博客网 时间:2024/06/08 08:54
Json解析之JsonArray 附加Gson生成与解析
Json解析之JsonArray String str = "{\"phone\" : [\"12345678\", \"87654321\"]}";
try { //注意List是实现Collection接口的 String str = "{\"phone\" : [\"12345678\", \"87654321\"]}"; JSONObject json = new JSONObject(str); JSONArray array = json.getJSONArray("phone"); StringBuffer sb = new StringBuffer(); for (int i = 0; i < array.length(); i++) { String s = (String) array.get(i); sb.append(s+"\n"); } textView.setText(sb.toString()); } catch (JSONException e) { e.printStackTrace(); }
json之生成与解析 List
// 生成List<String> list = new ArrayList<String>();list.add("aaa");list.add("bbb");Gson gson = new Gson();String str = gson.toJson(list);// 解析Gson gson = new Gson();List<String> list = gson.fromJson(toArr, new TypeToken<List<String>>() {}.getType());List<String> glist = new ArrayList<String>();for (String string : list) {glist .add(string);}
json之生成与解析 Bean
// 生成String str = gson.toJson(Class<?> cls);// 解析// 比如json字符串为:[{"name":"name0","age":0}] Class<?> cls bean = gson.fromJson(str, Class<?> cls);
对象解析json
Gson gson = new Gson(); java.lang.reflect.Type type = new TypeToken<JsonBean>() {}.getType(); JsonBean jsonBean = gson.fromJson(json, type);
用gson生成、解析json数据
// Serialize String userJSON = new Gson().toJson(user); // Deserialize User user = new Gson().fromJson(userJSON, User.class);
0 1
- Json解析之JsonArray 附加Gson生成与解析 对象解析json
- JSON解析 Gson解析方式 JSONObject JSONArray
- Gson解析json对象
- GSON与Json 解析
- json解析之gson解析
- JSON解析之-Gson
- JSON 之GSON 解析
- JSON 之GSON 解析
- JSON 之GSON 解析
- JSON 之GSON 解析
- JSON 之GSON 解析
- Json解析之gson
- JSON 之GSON 解析
- JSON 之GSON 解析
- JSON 之GSON 解析
- JSON 之GSON 解析
- JSON 之GSON 解析
- JSON解析之Gson
- ASP.NET MVC公共模板、节、分部视图等
- ASP.NET MVC异步加载分部视图
- PLSQL developer 连接不上64位Oracle 的解决方法
- WebService基于SoapHeader实现安全认证
- C#小技巧总结
- Json解析之JsonArray 附加Gson生成与解析 对象解析json
- 动态修改Web.config连接字符串
- EmitMapper,AutoMapper,NLiteMapper和手工映射性能大比拼
- 各大主流.Net的IOC框架性能测试比较
- myeclipse自定义java注释
- XmlDocument和XDocument搜索xml比较
- android handler消息机制
- Asp.Net MVC3 简单入门详解过滤器Filter(身份验证、缓存、防盗链、国际化等)
- Asp.Net 用户验证(自定义IPrincipal和IIdentity)