Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.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将来自php的json数据存储为字符串[]_Php_Android_Arrays_Json_String - Fatal编程技术网

Android将来自php的json数据存储为字符串[]

Android将来自php的json数据存储为字符串[],php,android,arrays,json,string,Php,Android,Arrays,Json,String,我有一个类似JSON的[{id:67,Title:1852,CustomLabel:66479},{id:68,Title:1859,CustomLabel:5478}……] 现在我会将标题存储在字符串[]中,以便将其传递给AutoCompleteTextView,但我是一个新手,不知道如何进行 有人能帮我吗?任何帮助都将不胜感激。提前感谢。试试: // [{"id":"67","Title":"1852","CustomLabel":"66479"}, {"id":"68","Title":

我有一个类似JSON的[{id:67,Title:1852,CustomLabel:66479},{id:68,Title:1859,CustomLabel:5478}……]

现在我会将标题存储在字符串[]中,以便将其传递给AutoCompleteTextView,但我是一个新手,不知道如何进行

有人能帮我吗?任何帮助都将不胜感激。提前感谢。

试试:

//  [{"id":"67","Title":"1852","CustomLabel":"66479"}, {"id":"68","Title":"1859","CustomLabel":"5478"}]
    public void s()
    {
        ArrayList<String> titleArr = new ArrayList<String>();
        JSONArray arr = new JSONArray(response);
        for(int i=0; i<arr.length(); i++)
        {
            JSONObject o = arr.getJSONObject(i);
            String id = o.optString("id");
            String title = o.optString("Title");
            String customLabel = o.optString("CustomLabel");
            titleArr.add(title);
        }
    }
你可以这样做:

 //You have jsonArray so Store it in jsonArray Object.
 int len = jsonArray.length();

 String[] titles = new String[len];

 for (int i = 0; i < len; i++) {
     final JSONObject e = jsonArray.getJSONObject(i);
     titles[i] =e.getString("Title");
 }
并将适配器设置为AutoCompleteTextView,如下所示:


你现在有什么问题??你不知道如何实现自动完成吗?谷歌会帮你的。所以,如果您遇到的问题不是如何实现,那么这只是一个解决方案?我的错,不知道如何将标题存储在字符串[]中。已实现自动完成文本视图。
 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_dropdown_item_1line, titles);
 AutoCompleteTextView textView = (AutoCompleteTextView)
            findViewById(R.id.autoCompleteTextView1);
 textView.setAdapter(adapter);