use of com.google.gson.JsonObject in project Minechem by iopleke.
the class ElementHandler method readFromStream.
private static void readFromStream(InputStream stream) {
JsonReader jReader = new JsonReader(new InputStreamReader(stream));
JsonParser parser = new JsonParser();
Set<Map.Entry<String, JsonElement>> elementsSet = parser.parse(jReader).getAsJsonObject().entrySet();
int count = 0;
for (Map.Entry<String, JsonElement> elementEntry : elementsSet) {
if (!elementEntry.getValue().isJsonObject()) {
continue;
}
JsonObject elementObject = elementEntry.getValue().getAsJsonObject();
ElementRegistry.getInstance().registerElement(Integer.parseInt(elementEntry.getKey()), elementObject.get("longName").getAsString(), elementObject.get("shortName").getAsString(), elementObject.get("form").getAsString(), elementObject.get("type").getAsString(), Integer.parseInt(elementObject.get("neutrons").getAsString()));
count++;
}
LogHelper.info("Total of " + count + " elements registered");
}
use of com.google.gson.JsonObject 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.JsonObject 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.JsonObject in project JsonPath by jayway.
the class JsonOrgJsonProvider method getMapValue.
@Override
public Object getMapValue(Object obj, String key) {
try {
JSONObject jsonObject = toJsonObject(obj);
Object o = jsonObject.get(key);
if (!jsonObject.has(key)) {
return UNDEFINED;
} else {
return unwrap(o);
}
} catch (JSONException e) {
throw new JsonPathException(e);
}
}
use of com.google.gson.JsonObject in project JsonPath by jayway.
the class JsonOrgJsonProvider method toIterable.
@Override
public Iterable<?> toIterable(Object obj) {
try {
if (isArray(obj)) {
JSONArray arr = toJsonArray(obj);
List<Object> values = new ArrayList<Object>(arr.length());
for (int i = 0; i < arr.length(); i++) {
values.add(unwrap(arr.get(i)));
}
return values;
} else {
JSONObject jsonObject = toJsonObject(obj);
List<Object> values = new ArrayList<Object>();
for (int i = 0; i < jsonObject.names().length(); i++) {
String key = (String) jsonObject.names().get(i);
Object val = jsonObject.get(key);
values.add(unwrap(val));
}
return values;
}
} catch (JSONException e) {
throw new JsonPathException(e);
}
}
Aggregations