本文整理汇总了Java中com.google.gson.stream.JsonReader.setLenient方法的典型用法代码示例。如果您正苦于以下问题:Java JsonReader.setLenient方法的具体用法?Java JsonReader.setLenient怎么用?Java JsonReader.setLenient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.stream.JsonReader
的用法示例。
在下文中一共展示了JsonReader.setLenient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
/**
* Deserialize the given JSON string to Java object.
*
* @param <T> Type
* @param body The JSON string
* @param returnType The type to deserialize into
* @return The deserialized Java object
*/
@SuppressWarnings("unchecked")
public <T> T deserialize(String body, Type returnType) {
try {
if (apiClient.isLenientOnJson()) {
JsonReader jsonReader = new JsonReader(new StringReader(body));
// see https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean)
jsonReader.setLenient(true);
return gson.fromJson(jsonReader, returnType);
} else {
return gson.fromJson(body, returnType);
}
} catch (JsonParseException e) {
// Fallback processing when failed to parse JSON form response body:
// return the response body string directly for the String return type;
// parse response body into date or datetime for the Date return type.
if (returnType.equals(String.class))
return (T) body;
else if (returnType.equals(Date.class))
return (T) apiClient.parseDateOrDatetime(body);
else throw(e);
}
}
示例2: fromJson
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public <T> T fromJson(JsonReader reader, Type typeOfT) throws JsonIOException, JsonSyntaxException {
boolean isEmpty = true;
boolean oldLenient = reader.isLenient();
reader.setLenient(true);
try {
reader.peek();
isEmpty = false;
T read = getAdapter(TypeToken.get(typeOfT)).read(reader);
reader.setLenient(oldLenient);
return read;
} catch (Throwable e) {
if (isEmpty) {
reader.setLenient(oldLenient);
return null;
}
throw new JsonSyntaxException(e);
} catch (Throwable e2) {
throw new JsonSyntaxException(e2);
} catch (Throwable e22) {
throw new JsonSyntaxException(e22);
} catch (Throwable th) {
reader.setLenient(oldLenient);
}
}
示例3: processDataBody
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
/**
* Processes a conference data body and calls the appropriate data type handlers
* to process each of the objects represented therein.
*
* @param dataBody The body of data to process
* @throws IOException If there is an error parsing the data.
*/
private void processDataBody(String dataBody) throws IOException {
JsonReader reader = new JsonReader(new StringReader(dataBody));
JsonParser parser = new JsonParser();
try {
reader.setLenient(true); // To err is human
// the whole file is a single JSON object
reader.beginObject();
while (reader.hasNext()) {
// the key is "rooms", "speakers", "tracks", etc.
String key = reader.nextName();
if (mHandlerForKey.containsKey(key)) {
// pass the value to the corresponding handler
mHandlerForKey.get(key).process(parser.parse(reader));
} else {
LOGW(TAG, "Skipping unknown key in conference data json: " + key);
reader.skipValue();
}
}
reader.endObject();
} finally {
reader.close();
}
}
示例4: fromJson
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public <T> T fromJson(JsonReader reader, Type typeOfT) throws JsonIOException,
JsonSyntaxException {
boolean isEmpty = true;
boolean oldLenient = reader.isLenient();
reader.setLenient(true);
try {
reader.peek();
isEmpty = false;
T object = getAdapter(TypeToken.get(typeOfT)).read(reader);
reader.setLenient(oldLenient);
return object;
} catch (Throwable e) {
if (isEmpty) {
reader.setLenient(oldLenient);
return null;
}
throw new JsonSyntaxException(e);
} catch (Throwable e2) {
throw new JsonSyntaxException(e2);
} catch (Throwable e22) {
throw new JsonSyntaxException(e22);
} catch (Throwable th) {
reader.setLenient(oldLenient);
}
}
示例5: deserialize
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
/**
* Deserialize the given JSON string to Java object.
*
* @param <T> Type
* @param body The JSON string
* @param returnType The type to deserialize into
* @return The deserialized Java object
*/
@SuppressWarnings("unchecked")
public <T> T deserialize(String body, Type returnType) {
try {
if (isLenientOnJson) {
JsonReader jsonReader = new JsonReader(new StringReader(body));
// see https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean)
jsonReader.setLenient(true);
return gson.fromJson(jsonReader, returnType);
} else {
return gson.fromJson(body, returnType);
}
} catch (JsonParseException e) {
// Fallback processing when failed to parse JSON form response body:
// return the response body string directly for the String return type;
if (returnType.equals(String.class))
return (T) body;
else throw (e);
}
}
示例6: gsonDeserialize
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public static <T> T gsonDeserialize(Gson gsonIn, Reader readerIn, Class<T> adapter, boolean lenient)
{
try
{
JsonReader jsonreader = new JsonReader(readerIn);
jsonreader.setLenient(lenient);
return gsonIn.getAdapter(adapter).read(jsonreader);
}
catch (IOException ioexception)
{
throw new JsonParseException(ioexception);
}
}
示例7: getProblem
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public static Problem getProblem(String jsonString) {
Problem problem =null;
try {
Gson gson = new Gson();
JsonReader jsonReader = new JsonReader(new StringReader(jsonString));
jsonReader.setLenient(true);
problem= gson.fromJson(jsonReader,Problem.class);
} catch (JsonSyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return problem;
}
示例8: fromJsonLenient
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
/**
* 将指定 Json 格式 (宽容模式) 的聊天内容转换为聊天组件
*
* @param json Json
* @return ChatComponent
* @throws JsonParseException 如果解析 Json 时错误则抛出异常
*/
public static ChatComponent fromJsonLenient(String json) {
Validate.notNull(json, "The json object is null.");
try {
JsonReader jsonReader = new JsonReader(new StringReader(json));
jsonReader.setLenient(true);
return GSON.getAdapter(ChatComponent.class).read(jsonReader);
} catch (IOException e) {
throw new JsonParseException(e);
}
}
示例9: getList
import com.google.gson.stream.JsonReader; //导入方法依赖的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;
}
示例10: getWorkOrderOf
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
private CmsWorkOrderSimpleBase getWorkOrderOf(String msgText, Class c) {
CmsWorkOrderSimpleBase wo;
JsonReader reader = new JsonReader(new StringReader(msgText));
reader.setLenient(true);
wo = gson.fromJson(reader, c);
return wo;
}
示例11: getuList
import com.google.gson.stream.JsonReader; //导入方法依赖的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;
}
示例12: setReaderOptions
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
void setReaderOptions(JsonReader reader) {
reader.setLenient(lenient);
}
示例13: JsonStreamParser
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
/**
* @param reader The data stream containing JSON elements concatenated to each other.
* @since 1.4
*/
public JsonStreamParser(Reader reader) {
parser = new JsonReader(reader);
parser.setLenient(true);
lock = new Object();
}
示例14: merge
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
void merge(Reader json, Message.Builder builder) throws IOException {
JsonReader reader = new JsonReader(json);
reader.setLenient(false);
merge(jsonParser.parse(reader), builder);
}
示例15: getJSONFromUrl
import com.google.gson.stream.JsonReader; //导入方法依赖的package包/类
public static <T> int getJSONFromUrl(String url,String tableName, Class<T> clazz,long last_sync_ts) throws IOException, JSONException, Exception {
if (url==null) {
return 0;
}
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("Cookie","[email protected]:False:185804764220139124118");
HttpResponse httpResponse = http_client.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
// All the work is done for you here :)
String jsonContent = EntityUtils.toString(httpEntity);
// Create a Reader from String
Reader stringReader = new StringReader(jsonContent);
//is = httpEntity.getContent();
reader = new JsonReader(stringReader);
reader.setLenient(true);
reader.beginObject();
int i = readMessage(reader, tableName, clazz, last_sync_ts);
httpEntity.consumeContent();
return i;
}