Header Ads

Header ADS

Json Parsing Key and Value

 

String ="[{"Gender":"Male"},{"Location":"jsr"},{"Choice Number":"10"},{"Select Date":"July 06, 2021"},{"Education":"Female"}]"


if (extrafield != null) {
try {
JSONArray jsonArray = new JSONArray(extrafield);
FormConfigEntites model;
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObj = jsonArray.getJSONObject(i);
String k = jsonObj.keys().next();
Log.i("dtavlaue", "Key: " + k + ", value: " + jsonObj.getString(k));
model = new FormConfigEntites();
String value = jsonObj.getString(k);
model.setLebel(k);
model.setValues(value);

list.add(model);
}

//String to jsonObject or use this
/* for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = new JSONObject(jsonArray.get(i).toString());
Iterator<String> keys = jsonObject.keys();
int counter = 0;
FormConfigEntites model = new FormConfigEntites();
while (keys.hasNext()) {
String key = keys.next();
String value = jsonObject.getString(key);

Log.i(TAG, "dtavlaue: "+value);

Logger.d(value);
if (counter == 0) {
model.setLebel(value);
} else if (counter == 1) {
model.setDataType(value);
} else {
model.setValues(value);
}
counter++;
}
list.add(model);
}*/


} catch (JSONException e) {
e.printStackTrace();
}
}

No comments

Theme images by Matt Vince. Powered by Blogger.