use of android.util.JsonToken in project platform_frameworks_base by android.
the class JsonParser method parse.
/**
* Consumes and parses exactly one JSON object from the {@link JsonReader}.
* The object's fields can only be objects, strings or arrays of strings.
*/
public static JSONObject parse(JsonReader reader) throws IOException, JSONException {
JSONObject output = new JSONObject();
String errorMsg = null;
reader.beginObject();
while (reader.hasNext()) {
String fieldName = reader.nextName();
if (output.has(fieldName)) {
errorMsg = "Duplicate field name.";
reader.skipValue();
continue;
}
JsonToken token = reader.peek();
if (token.equals(JsonToken.BEGIN_ARRAY)) {
output.put(fieldName, new JSONArray(parseArray(reader)));
} else if (token.equals(JsonToken.STRING)) {
output.put(fieldName, reader.nextString());
} else if (token.equals(JsonToken.BEGIN_OBJECT)) {
try {
output.put(fieldName, parse(reader));
} catch (JSONException e) {
errorMsg = e.getMessage();
}
} else {
reader.skipValue();
errorMsg = "Unsupported value type.";
}
}
reader.endObject();
if (errorMsg != null) {
throw new JSONException(errorMsg);
}
return output;
}
use of android.util.JsonToken in project android_frameworks_base by ResurrectionRemix.
the class JsonParser method parse.
/**
* Consumes and parses exactly one JSON object from the {@link JsonReader}.
* The object's fields can only be objects, strings or arrays of strings.
*/
public static JSONObject parse(JsonReader reader) throws IOException, JSONException {
JSONObject output = new JSONObject();
String errorMsg = null;
reader.beginObject();
while (reader.hasNext()) {
String fieldName = reader.nextName();
if (output.has(fieldName)) {
errorMsg = "Duplicate field name.";
reader.skipValue();
continue;
}
JsonToken token = reader.peek();
if (token.equals(JsonToken.BEGIN_ARRAY)) {
output.put(fieldName, new JSONArray(parseArray(reader)));
} else if (token.equals(JsonToken.STRING)) {
output.put(fieldName, reader.nextString());
} else if (token.equals(JsonToken.BEGIN_OBJECT)) {
try {
output.put(fieldName, parse(reader));
} catch (JSONException e) {
errorMsg = e.getMessage();
}
} else {
reader.skipValue();
errorMsg = "Unsupported value type.";
}
}
reader.endObject();
if (errorMsg != null) {
throw new JSONException(errorMsg);
}
return output;
}
use of android.util.JsonToken in project android_frameworks_base by crdroidandroid.
the class JsonParser method parse.
/**
* Consumes and parses exactly one JSON object from the {@link JsonReader}.
* The object's fields can only be objects, strings or arrays of strings.
*/
public static JSONObject parse(JsonReader reader) throws IOException, JSONException {
JSONObject output = new JSONObject();
String errorMsg = null;
reader.beginObject();
while (reader.hasNext()) {
String fieldName = reader.nextName();
if (output.has(fieldName)) {
errorMsg = "Duplicate field name.";
reader.skipValue();
continue;
}
JsonToken token = reader.peek();
if (token.equals(JsonToken.BEGIN_ARRAY)) {
output.put(fieldName, new JSONArray(parseArray(reader)));
} else if (token.equals(JsonToken.STRING)) {
output.put(fieldName, reader.nextString());
} else if (token.equals(JsonToken.BEGIN_OBJECT)) {
try {
output.put(fieldName, parse(reader));
} catch (JSONException e) {
errorMsg = e.getMessage();
}
} else {
reader.skipValue();
errorMsg = "Unsupported value type.";
}
}
reader.endObject();
if (errorMsg != null) {
throw new JSONException(errorMsg);
}
return output;
}
use of android.util.JsonToken in project android_frameworks_base by AOSPA.
the class JsonParser method parse.
/**
* Consumes and parses exactly one JSON object from the {@link JsonReader}.
* The object's fields can only be objects, strings or arrays of strings.
*/
public static JSONObject parse(JsonReader reader) throws IOException, JSONException {
JSONObject output = new JSONObject();
String errorMsg = null;
reader.beginObject();
while (reader.hasNext()) {
String fieldName = reader.nextName();
if (output.has(fieldName)) {
errorMsg = "Duplicate field name.";
reader.skipValue();
continue;
}
JsonToken token = reader.peek();
if (token.equals(JsonToken.BEGIN_ARRAY)) {
output.put(fieldName, new JSONArray(parseArray(reader)));
} else if (token.equals(JsonToken.STRING)) {
output.put(fieldName, reader.nextString());
} else if (token.equals(JsonToken.BEGIN_OBJECT)) {
try {
output.put(fieldName, parse(reader));
} catch (JSONException e) {
errorMsg = e.getMessage();
}
} else {
reader.skipValue();
errorMsg = "Unsupported value type.";
}
}
reader.endObject();
if (errorMsg != null) {
throw new JSONException(errorMsg);
}
return output;
}
use of android.util.JsonToken in project android_frameworks_base by DirtyUnicorns.
the class JsonParser method parse.
/**
* Consumes and parses exactly one JSON object from the {@link JsonReader}.
* The object's fields can only be objects, strings or arrays of strings.
*/
public static JSONObject parse(JsonReader reader) throws IOException, JSONException {
JSONObject output = new JSONObject();
String errorMsg = null;
reader.beginObject();
while (reader.hasNext()) {
String fieldName = reader.nextName();
if (output.has(fieldName)) {
errorMsg = "Duplicate field name.";
reader.skipValue();
continue;
}
JsonToken token = reader.peek();
if (token.equals(JsonToken.BEGIN_ARRAY)) {
output.put(fieldName, new JSONArray(parseArray(reader)));
} else if (token.equals(JsonToken.STRING)) {
output.put(fieldName, reader.nextString());
} else if (token.equals(JsonToken.BEGIN_OBJECT)) {
try {
output.put(fieldName, parse(reader));
} catch (JSONException e) {
errorMsg = e.getMessage();
}
} else {
reader.skipValue();
errorMsg = "Unsupported value type.";
}
}
reader.endObject();
if (errorMsg != null) {
throw new JSONException(errorMsg);
}
return output;
}
Aggregations