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);
}
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;
}
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");
}
}
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());
}
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;
}
Aggregations