0

APIからいくつかのjson配列を取得しているとします

[{"id":1,"title":"title","description":"description","vote":null,"created_at":"2013-11-12T21:08:10.922Z","updated_at":"2013-11-12T21:08:10.922Z"}]

これをurlからオブジェクトjsonとして取得したいSomeURL_Some

public class Some implements Serializable {

    private String id;
    private String title;
    private String description;
    private String vote;
    private String created_at;
    private String updated_at;
    }//with all getters and setters

.

public List<Some> getSome() throws IOException {
        try {
            HttpRequest request = execute(HttpRequest.get(URL_Some));
            SomeWrapper response = fromJson(request, SomeWrapper.class);
            Field[] fields = response.getClass().getDeclaredFields();
            for (int i=0; i<fields.length; i++)
            {
                try {
                    Log.i("TAG", (String) fields[i].get(response));
                } catch (IllegalAccessException e) {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                }
                Log.i("TAG", fields[i].getName());
            }
            if (response != null && response.results != null)
                return response.results;
            return Collections.emptyList();
        } catch (HttpRequestException e) {
            throw e.getCause();
        }
    }

そしてSomeWrapper単純に

private static class SomeWrapper {

        private List<Some> results;
    }

問題は、私がこのメッセージを受け取り続けることです

java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY

PS:私は使用します

import com.google.gson.Gson;

import com.google.gson.GsonBuilder;

import com.google.gson.JsonParseException;
4

2 に答える 2