当前位置: 首页>>代码示例>>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;未经允许,请勿转载。