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


Java JsonReader.setLenient方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:osimloeff,項目名稱:PI-Web-API-Client-Java-Android,代碼行數:31,代碼來源:JSON.java

示例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);
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:25,代碼來源:Gson.java

示例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();
    }
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:33,代碼來源:ConferenceDataHandler.java

示例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);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:26,代碼來源:Gson.java

示例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);
    }
}
 
開發者ID:cliffano,項目名稱:swaggy-jenkins,代碼行數:28,代碼來源:JSON.java

示例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);
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:14,代碼來源:JsonUtils.java

示例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;
}
 
開發者ID:xdstudent,項目名稱:ZhiHuIndex-master,代碼行數:14,代碼來源:GsonTool.java

示例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);
    }
}
 
開發者ID:McMoonLakeDev,項目名稱:MoonLakeChat,代碼行數:18,代碼來源:ChatSerializer.java

示例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;
}
 
開發者ID:xdstudent,項目名稱:ZhiHuIndex-master,代碼行數:20,代碼來源:GsonTool.java

示例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;
}
 
開發者ID:oneops,項目名稱:oneops,代碼行數:8,代碼來源:Listener.java

示例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;
}
 
開發者ID:xdstudent,項目名稱:ZhiHuIndex-master,代碼行數:15,代碼來源:GsonTool.java

示例12: setReaderOptions

import com.google.gson.stream.JsonReader; //導入方法依賴的package包/類
void setReaderOptions(JsonReader reader) {
  reader.setLenient(lenient);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:4,代碼來源:GsonMessageBodyProvider.java

示例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();
}
 
開發者ID:odoo-mobile-intern,項目名稱:odoo-work,代碼行數:10,代碼來源:JsonStreamParser.java

示例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);
}
 
開發者ID:SeldonIO,項目名稱:seldon-core,代碼行數:6,代碼來源:JsonFormat.java

示例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;


}
 
開發者ID:tiberiusteng,項目名稱:financisto1-holo,代碼行數:31,代碼來源:FlowzrSyncEngine.java


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