خرید بک لینک

Vote count: 0

I am trying to convert string into json array and the iterate over it.

            String name = "lokesh";
            String response = "[{"name":"lokesh"}, {"name":"cherukuri"}]";

            JsonArray jsonArray = gson.fromJson(response, JsonArray.class);
            for (int i = 0; i < jsonArray.size(); i++) {
                JsonObject jsonObject = jsonArray.get(i).getAsJsonObject();
                System.out.println(jsonObject.get("name"));
                if (jsonObject.get("name").toString().equals(name)) {
                    System.out.println("equal");
                }
            }

Problem: The If condition inside loop is not true because of quotes. because this line

   System.out.println(jsonObject.get("name")); // printed "lokesh"

    and System.out.println(name); //printed lokesh

Am i using GSON in a wrong way?

asked 2 mins ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 26 خرداد 1395 ساعت: 8:35

صفحه بندی