我在解码json字符串时遇到困难。以下是我的json字符串:
{
"udeals":"[{\"vName\":\"bussinessname3\",\"vAddress\":\"address3\",\"vState\":\"Kerala\",\"vZip\":\"232\",\"vCountry\":\"Algeria\",\"id\":\"3\",\"dealCategoryID\":\"2\",\"dealCaption\":\"deal3\",\"dealurl\":\"http:\\/\\/192.168.0.8\\/ppppp\\/deals\\/deal3-3\\/\",\"dealImage\":\"http:\\/\\/192.168.0.8\\/ppppp\\/images\\/deals\\/thumb390x256\\/Duizl1.jpg\",\"dealPrice\":\"50.00\",\"dealCost\":\"100.00\",\"dealSave\":-50,\"dealOfferRate\":\"50.00\",\"jsDeadLine\":{\"seconds\":0,\"minutes\":0,\"hours\":0,\"mday\":5,\"wday\":3,\"mon\":1,\"year\":2011,\"yday\":4,\"weekday\":\"Wednesday\",\"month\":\"January\",\"0\":1294165800},\"unlockedStamp\":{\"seconds\":53,\"minutes\":56,\"hours\":18,\"mday\":5,\"wday\":3,\"mon\":1,\"year\":2011,\"yday\":4,\"weekday\":\"Wednesday\",\"month\":\"January\",\"0\":1294234013},\"description\":\"Google URL Shortener at goo.gl is used by Google products to create short URLs that can be easily shared, tweeted, or emailed to friends.\"},{\"vName\":\"bussinessname20010\",\"vAddress\":\"address20010\",\"vState\":\"Kerala\",\"vZip\":\"232\",\"vCountry\":\"Argentina\",\"id\":\"20010\",\"dealCategoryID\":\"2\",\"dealCaption\":\"deal20010\",\"dealurl\":\"http:\\/\\/192.168.0.8\\/ppppp\\/deals\\/deal20010-20010\\/\",\"dealImage\":\"http:\\/\\/192.168.0.8\\/ppppp\\/images\\/deals\\/thumb390x256\\/oCcfTj.jpg\",\"dealPrice\":\"50.00\",\"dealCost\":\"100.00\",\"dealSave\":-50,\"dealOfferRate\":\"50.00\",\"jsDeadLine\":{\"seconds\":0,\"minutes\":0,\"hours\":0,\"mday\":28,\"wday\":2,\"mon\":12,\"year\":2010,\"yday\":361,\"weekday\":\"Tuesday\",\"month\":\"December\",\"0\":1293474600},\"unlockedStamp\":{\"seconds\":53,\"minutes\":56,\"hours\":18,\"mday\":5,\"wday\":3,\"mon\":1,\"year\":2011,\"yday\":4,\"weekday\":\"Wednesday\",\"month\":\"January\",\"0\":1294234013},\"description\":\"this is\"}]"
}
任何人都可以给我一个解决方案,以解决如何在Android中解析此问题…
可以使用以下代码解析此json。
str="<The Json>"
try {
JSONObject jObject=new JSONObject(str);
JSONArray menuObject = new JSONArray(jObject.getString("udeals"));
for (int i = 0; i<menuObject.length(); i++) {
System.out.println("length="+menuObject.length());
System.out.println("vName="+menuObject.getJSONObject(i)
.getString("vName"));
System.out.println("vAddress="+menuObject.getJSONObject(i).getString(
"vAddress"));
System.out.println("vState="+menuObject.getJSONObject(i)
.getString("vState"));
System.out.println("vZip="+menuObject.getJSONObject(i).getString(
"vZip"));
System.out.println("vCountry="+menuObject.getJSONObject(i)
.getString("vCountry"));
System.out.println("dealCategoryID="+menuObject.getJSONObject(i)
.getString("dealCategoryID"));
System.out.println("dealCaption="+menuObject.getJSONObject(i).getString(
"dealCaption"));
System.out.println("dealImage="+menuObject.getJSONObject(i)
.getString("dealImage"));
System.out.println("dealPrice="+menuObject.getJSONObject(i).getString(
"dealPrice"));
System.out.println("dealCost="+menuObject.getJSONObject(i)
.getString("dealCost"));
System.out.println("dealSave="+menuObject.getJSONObject(i).getString(
"dealSave"));
System.out.println("dealOfferRate="+menuObject.getJSONObject(i)
.getString("dealOfferRate"));
System.out.println("jsDeadLine="+menuObject.getJSONObject(i).getString(
"jsDeadLine"));
jsDeadLine=menuObject.getJSONObject(i).getString("jsDeadLine");
JSONObject deadLine= new JSONObject(jsDeadLine);
String seconds = deadLine.getString("seconds");
String minutes = deadLine.getString("minutes");
String hours = deadLine.getString("hours");
String mday = deadLine.getString("mday");
String wday = deadLine.getString("wday");
String mon = deadLine.getString("mon");
String year = deadLine.getString("year");
String yday = deadLine.getString("yday");
String weekday = deadLine.getString("weekday");
String month = deadLine.getString("month");
System.out.println("seconds:"+seconds);
System.out.println("minutes:"+minutes);
System.out.println("hours:"+hours);
System.out.println("unlockedStamp="+menuObject.getJSONObject(i)
.getString("unlockedStamp"));
unlockedStamp=menuObject.getJSONObject(i).getString("unlockedStamp");
JSONObject unlocked= new JSONObject(unlockedStamp);
String unlockedseconds = unlocked.getString("seconds");
String unlockedminutes = unlocked.getString("minutes");
String unlockedhours = unlocked.getString("hours");
String unlockedmday = unlocked.getString("mday");
String unlockedwday = unlocked.getString("wday");
String unlockedmon = unlocked.getString("mon");
String unlockedyear = unlocked.getString("year");
String unlockedyday = unlocked.getString("yday");
String unlockedweekday = unlocked.getString("weekday");
String unlockedmonth = unlocked.getString("month");
System.out.println("unlockedseconds:"+unlockedseconds);
System.out.println("unlockedminutes:"+unlockedminutes);
System.out.println("unlockedhours:"+unlockedhours);
System.out.println("description="+menuObject.getJSONObject(i).getString(
"description"));
System.out.println("id="+menuObject.getJSONObject(i)
.getString("id"));
System.out.println("dealurl="+menuObject.getJSONObject(i).getString(
"dealurl"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
问题内容: 我在Android的JSON解析中进行了很多搜索,但并不太确定。关于JSON解析,实际上有一个简短的想法,但还不清楚。 如何在应用程序中实现JSON解析? 问题答案: 这是一个非常简单的JSON字符串 为了得到它的值,使用像这样: 这是一个稍微复杂的json字符串 为了从此用途中提取值 希望这个对你有帮助...........
问题内容: 我正在尝试解析这种结构:(它使我发疯,并且我尝试了我能想到的一切。但是我不是很有经验) “ topDrop”就像文件名吗?player是一个JSONArray,包含5个播放器JSONObject。但是在JSON术语中,最重要的是什么。我在JSON验证程序上签出有效的凭证,我需要这样的凭证: topDrop作为JSONObject Player,作为JSONArray,并循环遍历数组中的
问题内容: 这是我的json数据 如何解码呢? 问题答案: 您应该能够使用org.json包进行解码。从这里: 只需使用自己的JSON即可。
本文向大家介绍Android中gson、jsonobject解析JSON的方法详解,包括了Android中gson、jsonobject解析JSON的方法详解的使用技巧和注意事项,需要的朋友参考一下 JSON的定义: 一种轻量级的数据交换格式,具有良好的可读和便于快速编写的特性。业内主流技术为其提供了完整的解决方案(有点类似于正则表达式 ,获得了当今大部分语言的支持),从而可以在不同平台间进行数据
所以基本上我使用的是Google的Places API,我想要从JSON到我的回收器视图的特定数据。我试着用凌空抽射,但它给了我一个空白屏幕或不断崩溃。所以有人能帮助我如何获得数据并显示具体的数据吗…这是我尝试的代码 LoadPlacesActivity.java places.java }这是logcat的截图
问题内容: 我正在尝试使用Google Maps API来获取路线时间。我希望创建一个URL,获取JSON响应,然后检查该响应的旅行持续时间。创建JSON对象后,我在导航时会遇到麻烦。对我来说,这表明我要么弄乱了获取响应,要么浏览JSON对象。如果您能窥见我从网络教程中拼凑而成的零碎代码,我将不胜感激。 此代码旨在获取响应。它被try / catch包围,并且没有触发任何错误。 这段代码的目的是获