如何解析而不在android系统密钥的JSON? [英] How to parse a JSON without key in android?

查看:132
本文介绍了如何解析而不在android系统密钥的JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我有一种简单的JSON响应的,我在JSON曾与密钥,但这一回应我只有值,请看到响应如下

JSON

  {
状态:成功,
国家:
{
1:阿富汗
},
{
2:阿尔巴尼亚
},
{
3:阿尔及利亚
},
{
4:美国萨摩亚
},
{
5:安道尔
},
{
6:安哥拉
},
{
7:安圭拉
},
{
8:南极人
},
{
9:安提瓜和巴布达
},
{
10:阿根廷队
},
{.....




上。所以..

所以我想分析这个JSON,并希望把两个值中一个HashMap的ArrayList中,我下面的工作,但是没有找到路径来进行,希望有哥们会帮我。

code

  jsonObj =新的JSONObject(jsonStr);
                如果(jsonObj.has(国家)){                    CountryArray = jsonObj.getJSONArray(国家);
                    如果(CountryArray =空&放大器;!&放大器;!CountryArray.length()= 0){
                        //通过所有联系人循环
                        System.out的
                                .println(::::::::::::::::我的才华大小:::::::::::
                                        + CountryArray.length());


解决方案

在状态,国家,所有的1,2等的JSON数组国家的所有按键,因此,必须是双引号。总之,你的JSON是无效的。
例如:

  {
状态:成功,
国:
{
1:阿富汗
}
]}

Hi i am having a simple type of json response ,I have worked on JSON with keys but in this response i only have the values,Please see the response as below

json

{
status: "success",
country: [
{
1: "Afghanistan"
},
{
2: "Albania"
},
{
3: "Algeria"
},
{
4: "American Samoa"
},
{
5: "Andorra"
},
{
6: "Angola"
},
{
7: "Anguilla"
},
{
8: "Antarctica"
},
{
9: "Antigua and Barbuda"
},
{
10: "Argentina"
},
{.....
.
.
.
.
.so on..

So i want to parse this JSON and want to put both the values in an ArrayList of Hashmap,I have worked as below,But find no path to proceed,Hope some buddy will help me.

code

jsonObj = new JSONObject(jsonStr);
                if (jsonObj.has("country")) {

                    CountryArray = jsonObj.getJSONArray("country");
                    if (CountryArray != null && CountryArray.length() != 0) {
                        // looping through All Contacts
                        System.out
                                .println("::::::::::::::::my talent  size:::::::::::"
                                        + CountryArray.length());

解决方案

The "status","country" and all the "1","2", etc in the json array "country" are all keys and hence, must be in double quotes. In short, your JSON is invalid. Example:

{
"status": "success",
"country": [
{
"1": "Afghanistan"
}
]}

这篇关于如何解析而不在android系统密钥的JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆