Search in sources :

Example 6 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project jphp by jphp-compiler.

the class JsonFunctions method json_decode.

public static Memory json_decode(Environment env, String json, boolean assoc, int depth) {
    MemoryDeserializer memoryDeserializer = new MemoryDeserializer();
    memoryDeserializer.setEnv(env);
    GsonBuilder gsonBuilder = JsonExtension.createGsonBuilderForDecode(memoryDeserializer);
    memoryDeserializer.setAssoc(assoc);
    memoryDeserializer.setMaxDepth(depth);
    Gson gson = gsonBuilder.create();
    try {
        env.setUserValue(JsonFunctions.class.getName() + "#error", null);
        Memory r = gson.fromJson(json, Memory.class);
        if (r == null)
            return Memory.NULL;
        else
            return assoc ? r.toImmutable() : r;
    } catch (MemoryDeserializer.MaxDepthException e) {
        env.setUserValue(JsonFunctions.class.getName() + "#error", JsonConstants.JSON_ERROR_DEPTH);
    } catch (JsonSyntaxException e) {
        env.setUserValue(JsonFunctions.class.getName() + "#error", JsonConstants.JSON_ERROR_SYNTAX);
    } catch (JsonParseException e) {
        env.setUserValue(JsonFunctions.class.getName() + "#error", JsonConstants.JSON_ERROR_STATE_MISMATCH);
    }
    return Memory.NULL;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) GsonBuilder(com.google.gson.GsonBuilder) Memory(php.runtime.Memory) StringMemory(php.runtime.memory.StringMemory) Gson(com.google.gson.Gson) JsonParseException(com.google.gson.JsonParseException) MemoryDeserializer(org.develnext.jphp.json.gson.MemoryDeserializer)

Example 7 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project weiciyuan by qii.

the class NearbyTimeLineDao method get.

public NearbyStatusListBean get() throws WeiboException {
    Map<String, String> map = new HashMap<String, String>();
    map.put("access_token", access_token);
    map.put("lat", lat);
    map.put("long", long_fix);
    String jsonData = HttpUtility.getInstance().executeNormalTask(HttpMethod.Get, URLHelper.NEARBY_STATUS, map);
    try {
        NearbyStatusListBean value = new Gson().fromJson(jsonData, NearbyStatusListBean.class);
        if (value != null) {
            return value;
        }
    } catch (JsonSyntaxException e) {
        AppLogger.e(e.getMessage());
    }
    return null;
}
Also used : NearbyStatusListBean(org.qii.weiciyuan.bean.NearbyStatusListBean) JsonSyntaxException(com.google.gson.JsonSyntaxException) HashMap(java.util.HashMap) Gson(com.google.gson.Gson)

Example 8 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project weiciyuan by qii.

the class OAuthDao method getOAuthUserInfo.

public UserBean getOAuthUserInfo() throws WeiboException {
    String uidJson = getOAuthUserUIDJsonData();
    String uid = "";
    try {
        JSONObject jsonObject = new JSONObject(uidJson);
        uid = jsonObject.optString("uid");
    } catch (JSONException e) {
        AppLogger.e(e.getMessage());
    }
    Map<String, String> map = new HashMap<String, String>();
    map.put("uid", uid);
    map.put("access_token", access_token);
    String url = URLHelper.USER_SHOW;
    String result = HttpUtility.getInstance().executeNormalTask(HttpMethod.Get, url, map);
    Gson gson = new Gson();
    UserBean user = new UserBean();
    try {
        user = gson.fromJson(result, UserBean.class);
    } catch (JsonSyntaxException e) {
        AppLogger.e(result);
    }
    return user;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) JSONObject(org.json.JSONObject) UserBean(org.qii.weiciyuan.bean.UserBean) HashMap(java.util.HashMap) JSONException(org.json.JSONException) Gson(com.google.gson.Gson)

Example 9 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project weiciyuan by qii.

the class FriendGroupDao method getGroup.

public GroupListBean getGroup() throws WeiboException {
    String url = URLHelper.FRIENDSGROUP_INFO;
    Map<String, String> map = new HashMap<String, String>();
    map.put("access_token", access_token);
    String jsonData = HttpUtility.getInstance().executeNormalTask(HttpMethod.Get, url, map);
    Gson gson = new Gson();
    GroupListBean value = null;
    try {
        value = gson.fromJson(jsonData, GroupListBean.class);
    } catch (JsonSyntaxException e) {
        AppLogger.e(e.getMessage());
    }
    return value;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) GroupListBean(org.qii.weiciyuan.bean.GroupListBean)

Example 10 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project weiciyuan by qii.

the class FriendGroupTimeLineDao method getGSONMsgList.

public MessageListBean getGSONMsgList() throws WeiboException {
    String json = getMsgListJson();
    Gson gson = new Gson();
    MessageListBean value = null;
    try {
        value = gson.fromJson(json, MessageListBean.class);
    } catch (JsonSyntaxException e) {
        AppLogger.e(e.getMessage());
        return null;
    }
    if (value != null && value.getItemList().size() > 0) {
        TimeLineUtility.filterMessage(value);
    }
    return value;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) MessageListBean(org.qii.weiciyuan.bean.MessageListBean) Gson(com.google.gson.Gson)

Aggregations

JsonSyntaxException (com.google.gson.JsonSyntaxException)143 Gson (com.google.gson.Gson)100 HashMap (java.util.HashMap)38 Cursor (android.database.Cursor)33 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)19 MessageBean (org.qii.weiciyuan.bean.MessageBean)16 BadRequestException (co.cask.cdap.common.BadRequestException)14 GsonBuilder (com.google.gson.GsonBuilder)13 InputStreamReader (java.io.InputStreamReader)13 ContentValues (android.content.ContentValues)12 TimeLinePosition (org.qii.weiciyuan.bean.android.TimeLinePosition)12 Type (java.lang.reflect.Type)10 FileReader (java.io.FileReader)9 Reader (java.io.Reader)9 Path (javax.ws.rs.Path)9 CommentBean (org.qii.weiciyuan.bean.CommentBean)9 UserBean (org.qii.weiciyuan.bean.UserBean)9 MessageListBean (org.qii.weiciyuan.bean.MessageListBean)8 Map (java.util.Map)7