java.lang.IllegalStateException:预期为BEGIN_ARRAY,但位于第1行第1列路径$

时间:2019-08-07 08:52:15

标签: java android

我尝试在手机上使用它,并与我的三星A5 2017正常工作,但是当我尝试在三星s10 +节目中运行应用程序时:

  

java.lang.IllegalStateException:应为BEGIN_ARRAY,但为STRING   在第1行第1列的路径$

@Override
 protected void onPostExecute(String massage) {

     Type type = new TypeToken < ArrayList < HashMap < String, String >>> () {}.getType();

     Gson gson = new Gson();
     String temp = massage.replaceAll("\\\\", "");
     String temp2 = temp.replaceAll(Matcher.quoteReplacement("$"), "");
     String newMassage = temp2.substring(1, temp2.length() - 1);

     ArrayList < HashMap < String, String >> arr = gson.fromJson(newMassage, type);



     for (int i = 0; i < arr.size(); i++) {
         if (!Objects.equals(arr.get(i).get("region"), city)) {
             arr.get(i).clear();
         }
     }
 }

1 个答案:

答案 0 :(得分:0)

在杰森,

[...]均值数组

{...}卑鄙的对象

json数据的特殊性,首先删除“ $”,然后需要删除“ \”。

String temp = massage.replaceAll("\\\\", "");
String temp2= temp .replaceAll(Matcher.quoteReplacement("$"), "");

“ temp2”是json字符串数据。最后一步是删除第一个和最后一个引号。

String newMassage = temp2.substring(1, temp2.length()-1);

ArrayList<HashMap<String, String>> arr = gson.fromJson(newMassage, type);