【发布时间】:2017-03-02 08:36:06
【问题描述】:
我正在尝试将一个 json 数组放入 Recyclerview。当我只使用一个论点(store_textposition)时,一切正常,但是当我添加另一个论点(store_name)时,它给了我"Wrong 1st argument type. Found 'String' , required Integer"。
这是我的 json 数组:
{"action":"true","error":"","data":[{"_id":"58ad8d8ca49d0e11e21c4504","store_name":"firstStore","store_view":0,"store_textposition":null}]}
我在哪里得到错误:
private boolean parse()
{
try
{
JSONObject obj = new JSONObject(jsonData);
JSONArray ja = obj.getJSONArray("data");
JSONObject jo;
shops.clear();
for(int i=0;i<ja.length();i++)
{
jo=ja.getJSONObject(i);
String store_name = jo.getString("store_name");
String store_textposition = jo.getString("store_textposition");
shops.add(store_textposition,store_name);
}
return true;
}
catch (JSONException e)
{
e.printStackTrace();
return false;
}
}
【问题讨论】:
-
我不明白。这里有什么不清楚的地方?该错误明确表示第一个参数需要是一个整数,但你的是一个字符串。
-
shops对象有什么类型? -
我假设
shops是List<String>。我还将假设您正在尝试在列表中添加两个字符串。正确的方法是调用 add() 两次,每次调用每个字符串。编译器认为您正在尝试使用 add(index, item) 方法将字符串项添加到指定索引。 -
@AlinPandichi 我试过了,但它在不同的 recyclreviews 中显示了每个争论
-
shops 是你的模型类吗?