Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.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
如何在android volley上解析此JSON_Android_Json - Fatal编程技术网

如何在android volley上解析此JSON

如何在android volley上解析此JSON,android,json,Android,Json,这是我需要解析的输出。usertype\u name的值应存储到字符串数组中。请帮帮我 { 0: { usertype_name: "Member-Individual" }, 1: { usertype_name: "Member-Institutional" }, 2: { usertype_name: "Officer-Member" }, 3: { usertype_name: "Officer-Ad

这是我需要解析的输出。
usertype\u name
的值应存储到字符串数组中。请帮帮我

{
    0: {
    usertype_name: "Member-Individual"
    },
    1: {
    usertype_name: "Member-Institutional"
    },
    2: {
    usertype_name: "Officer-Member"
    },
    3: {
    usertype_name: "Officer-Admin"
    },
    4: {
    usertype_name: "Officer-President"
    },
    current_position: "Member-Individual"
}
在截取上解析JSON时,通常我会这样做:

public void onResponse(String s) {
    JSONArray array= new JSONArray(s.toString());
    for(int i = 0; i < array.length(); i++) {
        JSONObject object = array.getJSONObject(i);
        String text = object.getString("usertype_name");
    }
}

像这样更改json字符串

{
  "array": [
    "Member-Individual",
    "Member-Institutional",
    "Officer-Member"
  ],
  "current_position": "6"
}
php代码示例:

 <?php
    class User {
        public $array = array("Member-Individual", "Member-Institutional", "Officer-Member");
        public $current_position = "6";

        public function __construct() {

        }
    }



    $user = new User();

    echo json_encode($user);
?>


是的。。。您将不得不添加更多数据。你的密码在哪里?你已经用截击了吗?展示出来,事实上。。。这不是有效的JSON。整数和纯文本不能是键。请检查我的编辑。希望它真的有用,因为您没有有效的JSON如何使它成为有效的JSON,同时保持
当前位置
值?您能帮助我在php上如何做到这一点吗?这一点我不熟悉:(参考我已经编辑了答案。请看一看。
 <?php
    class User {
        public $array = array("Member-Individual", "Member-Institutional", "Officer-Member");
        public $current_position = "6";

        public function __construct() {

        }
    }



    $user = new User();

    echo json_encode($user);
?>