當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonSyntaxException.printStackTrace方法代碼示例

本文整理匯總了Java中com.google.gson.JsonSyntaxException.printStackTrace方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonSyntaxException.printStackTrace方法的具體用法?Java JsonSyntaxException.printStackTrace怎麽用?Java JsonSyntaxException.printStackTrace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.gson.JsonSyntaxException的用法示例。


在下文中一共展示了JsonSyntaxException.printStackTrace方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: log

import com.google.gson.JsonSyntaxException; //導入方法依賴的package包/類
@Override
public void log( String message ){
    final String logName = "OkHttp";
    if( !message.startsWith( "{" ) ){
        Log.d( logName, message );
        return;
    }
    try{
        String prettyPrintJson = new GsonBuilder()
                .setPrettyPrinting()
                .create()
                .toJson( new JsonParser().parse( message ) );
        Logger.init().methodCount( 1 ).hideThreadInfo();
        Logger.t( logName ).json( prettyPrintJson );
    }catch( JsonSyntaxException m ){
        Log.e( TAG, "html header parse failed" );
        m.printStackTrace();
        Log.e( logName, message );
    }
}
 
開發者ID:TheKhaeng,項目名稱:nongbeer-mvp-android-demo,代碼行數:21,代碼來源:HttpLogger.java

示例2: check

import com.google.gson.JsonSyntaxException; //導入方法依賴的package包/類
public static void check(String json, CheckCallback callback) {
    Status status = null;
    try {
        status = new Gson().fromJson(json, Status.class);
    } catch (JsonSyntaxException e) {
        e.printStackTrace();
    }

    if (status == null) {
        callback.onFailure("JSON格式錯誤。", 0);
    } else {
        if (status.getResult()) {
            callback.onPass();
        } else {
            callback.onFailure(status.getMessage(), status.getWhich());
        }
    }
}
 
開發者ID:SailFlorve,項目名稱:RunHDU,代碼行數:19,代碼來源:StatusJsonCheckHelper.java

示例3: log

import com.google.gson.JsonSyntaxException; //導入方法依賴的package包/類
@Override
public void log(@NonNull String message) {
    if (!message.startsWith("{") && !message.startsWith("[")) {
        largeLog(TAG, message);
        return;
    }
    try {
        String prettyPrintJson = new GsonBuilder()
                .setPrettyPrinting()
                .create()
                .toJson(new JsonParser().parse(message));
        largeLog(TAG, prettyPrintJson);
    } catch (JsonSyntaxException exception) {
        largeLog(TAG, "html header parse failed");
        exception.printStackTrace();
        largeLog(TAG, message);
    }
}
 
開發者ID:akexorcist,項目名稱:Repository-ArchComponents,代碼行數:19,代碼來源:PrettyHttpLogger.java

示例4: testGsonOverwritingCapabilities

import com.google.gson.JsonSyntaxException; //導入方法依賴的package包/類
/**
 * Tests if GSON can be used to overwrite only those values from the default configuration file,
 * which are defined by the user.
 */
@Test
public void testGsonOverwritingCapabilities() {
   Gson gson = new Gson();
   TestAlgorithmConfiguration testAlgorithmConfiguration = new TestAlgorithmConfiguration();
   try {
      String jsonString = "{\"t\":1,\"p\":2,\"gradientStepIdentifier\":\"test\",\"l\":2, \"jsonObject\" = {\"a\":\"test\"}}";
      testAlgorithmConfiguration = gson.fromJson(jsonString, TestAlgorithmConfiguration.class);

      assertEquals("test", testAlgorithmConfiguration.getJsonObject().get("a").getAsString());

      String jsonString2 = "{\"t\":1,\"gradientStepIdentifier\":\"test\",\"l\":2}";
      TestAlgorithmConfiguration config2 = gson.fromJson(jsonString2, TestAlgorithmConfiguration.class);
      testAlgorithmConfiguration.copyValues(config2);
   } catch (JsonSyntaxException ex) {
      ex.printStackTrace();
   }
   assertEquals("test", testAlgorithmConfiguration.getGradientStepIdentifier());
   assertEquals(2, testAlgorithmConfiguration.getP(), 0.1);
   assertEquals(1, testAlgorithmConfiguration.getT());
}
 
開發者ID:Intelligent-Systems-Group,項目名稱:jpl-framework,代碼行數:25,代碼來源:GsonTest.java

示例5: readPingWidgetData

import com.google.gson.JsonSyntaxException; //導入方法依賴的package包/類
public static PingWidgetData readPingWidgetData(Context context, int widgetId) {
    PingWidgetData pingWidgetData = null;
    try {
        Gson gson = new Gson();
        String json = getPreferences(context).getString(PING_WIDGET_DATA + widgetId, "");
        pingWidgetData = gson.fromJson(json, PingWidgetData.class);

        //Fix for widgets with old data.
        if(pingWidgetData != null)
            resetPingWidgetDataIfNull(context, widgetId, pingWidgetData);


    } catch (JsonSyntaxException e) {
        e.printStackTrace();
    }
    return pingWidgetData;
}
 
開發者ID:abicelis,項目名稱:PingWidget,代碼行數:18,代碼來源:SharedPreferencesHelper.java

示例6: convertEntity

import com.google.gson.JsonSyntaxException; //導入方法依賴的package包/類
/**
 * 將json數據轉化為實體數據
 * @param jsonData json字符串
 * @param entityClass 類型
 * @return 實體
 */
public static <T> T convertEntity(String jsonData, Class<T> entityClass) {
    T entity = null;
    try {
        entity = sGson.fromJson(jsonData.toString(), entityClass);
    } catch (JsonSyntaxException e) {
        e.printStackTrace();
    }
    return entity;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:16,代碼來源:GsonHelper.java

示例7: convertEntities

import com.google.gson.JsonSyntaxException; //導入方法依賴的package包/類
/**
 * 將json數據轉化為實體列表數據
 * @param jsonData json字符串
 * @param entityClass 類型
 * @return 實體列表
 */
public static <T> List<T> convertEntities(String jsonData, Class<T> entityClass) {
    List<T> entities = new ArrayList<>();
    try {
        JsonArray jsonArray = sJsonParser.parse(jsonData).getAsJsonArray();
        for (JsonElement element : jsonArray) {
            entities.add(sGson.fromJson(element, entityClass));
        }
    } catch (JsonSyntaxException e) {
        e.printStackTrace();
    }
    return entities;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:GsonHelper.java

示例8: shouldShowMessage

import com.google.gson.JsonSyntaxException; //導入方法依賴的package包/類
public static boolean shouldShowMessage() {
    boolean enoughTimePassed = true;

    String json = DCSharedPreferences.loadString(DCSharedPreferences.DCSharedKey.LAST_MESSAGE_TIME);
    if (json != null) {
        try {
            Date lastDate = DCApiManager.gson.fromJson(json, Date.class);
            Date now = Calendar.getInstance().getTime();
            if (now.getTime() - lastDate.getTime() < 3600000) {
                enoughTimePassed = false;
            }
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
        }
    }

    if (enoughTimePassed) {
        Calendar calendar = Calendar.getInstance();
        int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
        if (hourOfDay >= 2 && hourOfDay < 11) {
            return true;
        } else if (hourOfDay >= 17 && hourOfDay < 24) {
            return true;
        }
        return true;
    }

    return false;
}
 
開發者ID:Dentacoin,項目名稱:aftercare-app-android,代碼行數:30,代碼來源:DCMessageFragment.java

示例9: updateDaysCounter

import com.google.gson.JsonSyntaxException; //導入方法依賴的package包/類
private void updateDaysCounter() {
    int day = DCSharedPreferences.loadInt(DCSharedPreferences.DCSharedKey.DAYS_COUNTER);
    Calendar today = Calendar.getInstance();
    String json = DCSharedPreferences.loadString(DCSharedPreferences.DCSharedKey.LAST_DATE_ADDED_DAYS);
    if (json != null) {
        try {
            Date lastDate = DCApiManager.gson.fromJson(json, Date.class);
            Calendar then = Calendar.getInstance();
            then.setTime(lastDate);

            if (today.get(Calendar.YEAR) == then.get(Calendar.YEAR) && today.get(Calendar.DAY_OF_YEAR) == then.get(Calendar.DAY_OF_YEAR)) {
                return;
            }
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
            return;
        }
    }

    day += 1;

    if (day > DCConstants.DAYS_OF_USE) {
        day = 1;
    }

    DCSharedPreferences.saveInt(DCSharedPreferences.DCSharedKey.DAYS_COUNTER, day);
    DCSharedPreferences.saveString(DCSharedPreferences.DCSharedKey.LAST_DATE_ADDED_DAYS, DCApiManager.gson.toJson(today.getTime()));
}
 
開發者ID:Dentacoin,項目名稱:aftercare-app-android,代碼行數:29,代碼來源:DCDashboardActivity.java

示例10: getList

import com.google.gson.JsonSyntaxException; //導入方法依賴的package包/類
/**TODO 轉換為指定的 對象
 * @param jsonString
 * @param type 指定對象的類型 ,即 T.class
 * @return
 */
public static List<Problem> getList(String jsonString) {
    List<Problem> problemList = new ArrayList<Problem>();
    try {
        Gson gson = new Gson();
        Type type = new TypeToken<List<Problem>>(){}.getType();
        JsonReader jsonReader = new JsonReader(new StringReader(jsonString));
        jsonReader.setLenient(true);
        problemList = gson.fromJson(jsonReader, type);
    } catch (JsonSyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return problemList;
}
 
開發者ID:xdstudent,項目名稱:ZhiHuIndex-master,代碼行數:20,代碼來源:GsonTool.java

示例11: fromJson

import com.google.gson.JsonSyntaxException; //導入方法依賴的package包/類
/**
 * @param json
 * @param classOfT
 * @return
 * @MethodName : fromJson
 * @Description : 用來將JSON串轉為對象,但此方法不可用來轉帶泛型的集合
 */
public static <T> Object fromJson(String json, Class<T> classOfT) {
    try {
        return gson.fromJson(json, (Type) classOfT);
    } catch (JsonSyntaxException e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:wp521,項目名稱:MyFire,代碼行數:16,代碼來源:JsonUtils.java

示例12: getuList

import com.google.gson.JsonSyntaxException; //導入方法依賴的package包/類
public static List<User> getuList(String jsonString) {
    List<User> uList = new ArrayList<User>();
    try {
        Gson gson = new Gson();
        Type type = new TypeToken<List<User>>(){}.getType();
        JsonReader jsonReader = new JsonReader(new StringReader(jsonString));
        jsonReader.setLenient(true);
        uList = gson.fromJson(jsonReader, type);
    } catch (JsonSyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return uList;
}
 
開發者ID:xdstudent,項目名稱:ZhiHuIndex-master,代碼行數:15,代碼來源:GsonTool.java

示例13: paresDataResult

import com.google.gson.JsonSyntaxException; //導入方法依賴的package包/類
private static GanApiResult paresDataResult(String jsonStr){
    if (jsonStr == null) return null;

    GanApiResult result = new GanApiResult();

    try {
        JsonParser parser = new JsonParser();
        JsonObject json = parser.parse(jsonStr).getAsJsonObject();

        if (json.has(GanDefine.JSON_KEY_ERROR)){
            result.setError(json.get(GanDefine.JSON_KEY_ERROR).getAsBoolean());
        }

        if (json.has(GanDefine.JSON_KEY_RESULTS)){
            List<ArticleItem> dataList = new ArrayList<>();
            JsonArray jsonArray = json.getAsJsonArray(GanDefine.JSON_KEY_RESULTS);
            for (int i = 0; i < jsonArray.size(); i++){
                dataList.add(convertJsonToReadItem((JsonObject) jsonArray.get(i)));
            }
            result.setResults(dataList);
        }
    } catch (JsonSyntaxException e) {
        e.printStackTrace();
    }

    return result;
}
 
開發者ID:androidDaniel,項目名稱:treasure,代碼行數:28,代碼來源:GanApiNetHelper.java

示例14: listBundle

import com.google.gson.JsonSyntaxException; //導入方法依賴的package包/類
public <T> ResultBundle<T> listBundle(String json, Class<T> classOfT) {
	ResultList<T> result = null;
	try {
		Type objType = new ParameterizedType() {

			@Override
			public Type[] getActualTypeArguments() {
				return new Type[] {classOfT};
			}

			@Override
			public Type getRawType() {
				return ResultList.class;
			}

			@Override
			public Type getOwnerType() {
				return null;
			}
			
		};
		result = GSON.fromJson(json, objType);
	} catch(JsonSyntaxException e) {
		LOG.error("無法解析的信息, 由於 " + e.getLocalizedMessage());
		e.printStackTrace();
	}
	check(result);
	return result;
}
 
開發者ID:TransientBuckwheat,項目名稱:nest-spider,代碼行數:30,代碼來源:ResultBundleResolver.java

示例15: serialize

import com.google.gson.JsonSyntaxException; //導入方法依賴的package包/類
@Override
public String serialize(Object value) {
	if (value == null) {
		return null;
	}
	try {
		return gson.toJson(value);
	}catch (JsonSyntaxException ex){
		ex.printStackTrace();
	}
	return null;
}
 
開發者ID:dracnis,項目名稱:VanillaPlus,代碼行數:13,代碼來源:GSon_1_8_2.java


注:本文中的com.google.gson.JsonSyntaxException.printStackTrace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。