本文整理匯總了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;
}