1
回答
用volley管理请求出错
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

@stormzhang 你好,想跟你请教个问题:我用你在“9gag”项目中的方式管理了请求,在GosnRequst中

protected Response<T> parseNetworkResponse(NetworkResponse response) {
        try {
            String json = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
            return Response.success(mGson.fromJson(json, mClazz),HttpHeaderParser.parseCacheHeaders(response));
        } catch (UnsupportedEncodingException e) {
            return Response.error(new ParseError(e));
        } catch (JsonSyntaxException e) {
            return Response.error(new ParseError(e));
        }

其中

Sting json="[{"ID":"5","name":"test","psd":"123","create_date":"2014-04-19 13:59:47"}]";




但是,每次运行到 

mGson.fromJson(json, mClazz)

的时候 就会抛

JsonSyntaxException

异常

我的mClass是 

User.UserRequestData.class



这是User类


public class User extends BaseModel{
    private static final HashMap<String, User> CACHE = new HashMap<String, User>();
    public String ID;
    public String name;
    public String psd;
    public String create_date;
    private static void addToCache(User user) {
        CACHE.put(user.ID, user);
    }

    private static User getFromCache(String id) {
        return CACHE.get(id);
    }

    public static User fromJson(String json) {
        return new Gson().fromJson(json, User.class);
    }

    public static User fromCursor(Cursor cursor) {
        String id = cursor.getString(cursor.getColumnIndex(UserDataHelper.UsersDBInfo.ID));
        User user = getFromCache(id);
        if (user != null) {
            return user;
        }
        user = new Gson().fromJson(
                cursor.getString(cursor.getColumnIndex(UserDataHelper.UsersDBInfo.NAME)),
                User.class);
        addToCache(user);
        return user;
    }

    public static class UserRequestData {
        public ArrayList<User> data;
    }


}

请问到达时哪里出问题了

万分感谢!!













<无标签>
举报
xaozu
发帖于4年前 1回/800阅
顶部