Json解析,新手求帮助

small-dream 2014-03-28 07:36:29
服务端返回的Json字符串如下

我应该怎么才能把它去取出来,里面有嵌套,怎么办?
...全文
1028 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
悲鸣秋 2014-03-29
  • 打赏
  • 举报
回复
我一般用$.getJSON("调用方法",map,function(data){ //然后 你想调用 ResultUserInfo var resultUserInfo = data.ResultUserInfo; //接着要调用里面的 如UserName var userName = resultUserInfo.UserName; })
huntor 2014-03-29
  • 打赏
  • 举报
回复
可以使用 json-path ,类似xpath的方式 http://code.google.com/p/json-path/
代码间的舞者 2014-03-29
  • 打赏
  • 举报
回复
引用 3 楼 huxiweng 的回复:
参考

JSONArray jsonArrays = new JSONArray(buf);
			for (int i = 0; i < jsonArrays.length(); i++) {
				JSONObject obj = jsonArrays.getJSONObject(i);
				long count = 0L;
				String categoryType = "";
				String catTypeToString = "";
				String url = "";
				if (obj.has("count")) {
					count = Long.valueOf(obj.optString("count"));
				}
				
				if (obj.has("cateType")) {
					categoryType = obj.optString("cateType");
				}
				
				String cateName = null;
				if (obj.has("cateName")) {
					cateName = obj.optString("cateName");
				}
				url = obj.optString("url");
				if (QuhaoConstant.test) {
					if(null != url &&!"".equals(url))
					{
						url = obj.getString("url").replace("http://localhost:9081/", QuhaoConstant.HTTP_URL);
					}
					
//					imgUrl = obj.getString("merchantImage").replace("http://localhost:9081/", "http://192.168.2.100:9081/");
					System.out.println(url);
				} else {
					url = obj.getString("merchantImage");
				}
				Category category = new Category(count, categoryType, cateName, url);
				categroys.add(category);
			}
版主,楼主是想要客户端,即js解析JSon的代码吧
leokelly001 2014-03-29
  • 打赏
  • 举报
回复
JSONObject解析
tony4geek 2014-03-29
  • 打赏
  • 举报
回复
循环解析 json
showjim 2014-03-28
  • 打赏
  • 举报
回复
试试fastCSharp
        class result
        {
            public bool ValidResult;
            public userInfo ResultUserLoginInfo;
            //...
        }
        class userInfo
        {
            public int UserId;
            //...
        }
            result result = fastCSharp.setup.cSharp.json.parse.Get<result>(json);
代码间的舞者 2014-03-28
  • 打赏
  • 举报
回复
好像用到eval eval(“【返回的对象】”)
teemai 2014-03-28
  • 打赏
  • 举报
回复
参考

JSONArray jsonArrays = new JSONArray(buf);
			for (int i = 0; i < jsonArrays.length(); i++) {
				JSONObject obj = jsonArrays.getJSONObject(i);
				long count = 0L;
				String categoryType = "";
				String catTypeToString = "";
				String url = "";
				if (obj.has("count")) {
					count = Long.valueOf(obj.optString("count"));
				}
				
				if (obj.has("cateType")) {
					categoryType = obj.optString("cateType");
				}
				
				String cateName = null;
				if (obj.has("cateName")) {
					cateName = obj.optString("cateName");
				}
				url = obj.optString("url");
				if (QuhaoConstant.test) {
					if(null != url &&!"".equals(url))
					{
						url = obj.getString("url").replace("http://localhost:9081/", QuhaoConstant.HTTP_URL);
					}
					
//					imgUrl = obj.getString("merchantImage").replace("http://localhost:9081/", "http://192.168.2.100:9081/");
					System.out.println(url);
				} else {
					url = obj.getString("merchantImage");
				}
				Category category = new Category(count, categoryType, cateName, url);
				categroys.add(category);
			}
teemai 2014-03-28
  • 打赏
  • 举报
回复
用JSONObject解析好了
编程点滴 2014-03-28
  • 打赏
  • 举报
回复
Json.getJson()就可以获取到一个json对象啊,这样就可以处理嵌套了

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧