本文整理汇总了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 );
}
}
示例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());
}
}
}
示例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);
}
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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()));
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}