-4
我想把一个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;
}
}
我不明白。这里不清楚什么?该错误明确指出,第一个参数需要是一个整数,但你的是一个字符串。 – Tom
什么类型有“商店”对象? – Ircover
我会假设'商店'是一个'列表'。我也会假设你正在试图在列表中添加两个字符串。做到这一点的正确方法是每次调用add()两次,每次String。编译器认为你正在尝试使用方法add(index,item),它将String项添加到指定的索引。 –