Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在android中解析json数组中没有键的json对象值?_Java_Android_Json_Android Studio - Fatal编程技术网

Java 如何在android中解析json数组中没有键的json对象值?

Java 如何在android中解析json数组中没有键的json对象值?,java,android,json,android-studio,Java,Android,Json,Android Studio,如何解析下面的json数组,我的目标是传递没有值的对象 我已经尝试使用json对象的键返回json对象,但我的问题是如何在textview中显示没有键的json [ [ "Why are teachers being paid poorly?", { "answer": "minimum wage is 30,000", "candidate": "Nnamdi kalu" }, "what is the minimum wage

如何解析下面的json数组,我的目标是传递没有值的对象

我已经尝试使用json对象的键返回json对象,但我的问题是如何在textview中显示没有键的json

[
[
    "Why are teachers being paid poorly?",
    {
        "answer": "minimum wage is 30,000",
        "candidate": "Nnamdi kalu"
    },
    "what is the minimum wage for teachers?",
    {
        "answer": "net worth is $200,000",
        "candidate": "Nnamdi kalu"
    },
    {
        "answer": "Teachers minimum wage is $200,000",
        "candidate": "Nnamdi kalu"
    },
    "What can you do to improve the Agriculture section?",
    "why do you delay in salary payment and how do you intend to solve late payment of salary?",
    "Checking if i can ask you more questions, can i ?",
    "What can you do to improve the football game?",
    "what is your name",
    "what are your agenda",
    "What can you do to help young entrepreneurs?"
 ]
]

我希望以测验应用程序的形式显示数据?

在这种情况下,您有一个带有多种可能值类型的
JSONArray
。数组中的每个元素可以是
字符串
JSONObject

您可以使用
JSONArray.get()
方法获取每个元素,然后使用
instanceof
操作符检查元素是
字符串还是
JSONObject

假设您发布的示例存储在名为
数组的
JSONArray
中。您可以编写以下代码:

for (int i = 0; i < array.length(); i++) {
    Object o = array.get(i);
    if (o instanceof JSONObject) {
        System.out.println("object");
    } else if (o instanceof String) {
        System.out.println("string");
    }
}
现在,您可以用真实代码替换我的
System.out.println()
调用,您应该已经上路了

string
object
string
object
object
string
...