Search in sources :

Example 16 with JsonParser

use of com.google.gson.JsonParser in project musicbrainz-android by jdamcd.

the class LastFmClient method parseResult.

private LastFmArtist parseResult(InputStream stream) {
    Reader reader = new InputStreamReader(stream);
    JsonObject obj = new JsonParser().parse(reader).getAsJsonObject();
    return new Gson().fromJson(obj.get("artist"), LastFmArtist.class);
}
Also used : InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) JsonParser(com.google.gson.JsonParser)

Example 17 with JsonParser

use of com.google.gson.JsonParser in project musicbrainz-android by jdamcd.

the class WikipediaClient method parseResult.

private String parseResult(InputStream stream) {
    Reader reader = new InputStreamReader(stream);
    JsonObject obj = new JsonParser().parse(reader).getAsJsonObject();
    WikipediaBio response = new Gson().fromJson(obj.get("mobileview"), WikipediaBio.class);
    return response.sections.get(0).text;
}
Also used : WikipediaBio(org.musicbrainz.mobile.async.external.result.WikipediaBio) InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) JsonParser(com.google.gson.JsonParser)

Example 18 with JsonParser

use of com.google.gson.JsonParser in project nmid-headline by miao1007.

the class JPushReceiver method processClick.

private void processClick(Context context, Bundle bundle) {
    //打开自定义的Activity
    if (bundle.getString(JPushInterface.EXTRA_EXTRA).trim().length() > 3) {
        JsonObject newObj = new JsonParser().parse(bundle.getString(JPushInterface.EXTRA_EXTRA)).getAsJsonObject();
        Feed feed = new Feed(newObj.get(HeadlineService.ID).getAsInt(), newObj.get(HeadlineService.CATEGORY).getAsInt());
        DetailedActivity.startActivity(context, feed);
    } else {
        Log.e(TAG, "cn.jpush.android.EXTRA IllegalFormatException");
    }
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser) Feed(cn.edu.cqupt.nmid.headline.support.repository.headline.bean.Feed)

Example 19 with JsonParser

use of com.google.gson.JsonParser in project Avengers by saulmm.

the class GsonDeserializersTest method testThatACollectionDeserialzierDeserializesACollection.

@Test
public void testThatACollectionDeserialzierDeserializesACollection() throws Exception {
    MarvelResultsDeserializer<CollectionItem> marvelResultsDeserializer = new MarvelResultsDeserializer<>();
    JsonElement collectionElement = new JsonParser().parse(getComicsCollectionJsonString());
    Type t = new TypeToken<List<CollectionItem>>() {
    }.getType();
    List<CollectionItem> collectionList = marvelResultsDeserializer.deserialize(collectionElement, t, mock(JsonDeserializationContext.class));
    assertThat(collectionList.isEmpty(), is(false));
    assertNotNull(collectionList.get(0).getThumbnail());
}
Also used : Type(java.lang.reflect.Type) JsonDeserializationContext(com.google.gson.JsonDeserializationContext) JsonElement(com.google.gson.JsonElement) List(java.util.List) CollectionItem(saulmm.avengers.entities.CollectionItem) MarvelResultsDeserializer(saulmm.avengers.rest.utils.deserializers.MarvelResultsDeserializer) JsonParser(com.google.gson.JsonParser) Test(org.junit.Test)

Example 20 with JsonParser

use of com.google.gson.JsonParser in project play-cookbook by spinscale.

the class ApiPlugin method getJson.

private Object getJson(Class clazz, String name) {
    try {
        String data = IOUtils.toString(Request.current().body);
        JsonElement jsonElem = new JsonParser().parse(data);
        if (jsonElem.isJsonObject()) {
            JsonObject json = (JsonObject) jsonElem;
            if (json.has(name)) {
                JsonObject from = json.getAsJsonObject(name);
                Object result = gson.fromJson(from, clazz);
                return result;
            }
        }
    } catch (Exception e) {
        Logger.error("Problem rendering JSON: %s", e.getMessage());
    }
    return null;
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) JsonParseException(com.google.gson.JsonParseException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) JsonParser(com.google.gson.JsonParser)

Aggregations

JsonParser (com.google.gson.JsonParser)323 JsonObject (com.google.gson.JsonObject)263 JsonElement (com.google.gson.JsonElement)88 JsonArray (com.google.gson.JsonArray)49 IOException (java.io.IOException)39 Gson (com.google.gson.Gson)31 InputStreamReader (java.io.InputStreamReader)24 HashMap (java.util.HashMap)20 Map (java.util.Map)18 ArrayList (java.util.ArrayList)16 JsonReader (com.google.gson.stream.JsonReader)11 Test (org.junit.Test)11 AssetManager (android.content.res.AssetManager)10 InputStream (java.io.InputStream)10 Type (java.lang.reflect.Type)10 URL (java.net.URL)9 Test (org.testng.annotations.Test)9 UserType (com.glitchcog.fontificator.bot.UserType)8 EmojiType (com.glitchcog.fontificator.emoji.EmojiType)8 JsonParseException (com.google.gson.JsonParseException)8