Java tutorial
//package com.java2s; import java.lang.reflect.Field; import org.json.JSONException; import org.json.JSONObject; import android.app.Activity; import android.view.View; import android.widget.ImageView; import android.widget.TextView; public class Main { public static void jsonToAndroidLayoutMapper(Class<?> classObj, JSONObject json, String prefixStr, Activity view) throws JSONException { for (int i = 0; i < json.names().length(); i++) { String keyStr = (String) json.names().get(i); Field fieldObj = null; try { fieldObj = classObj.getField(prefixStr + "_" + keyStr.toLowerCase()); } catch (NoSuchFieldException e) { continue; } Object layoutObj = null; try { layoutObj = fieldObj.get(fieldObj); } catch (IllegalAccessException e) { continue; } Integer layoutIntvalue = (Integer) layoutObj; View selectedView = view.findViewById(layoutIntvalue); if (selectedView instanceof TextView) { TextView textView = (TextView) selectedView; textView.setText((String) json.get(keyStr)); } else if (selectedView instanceof ImageView) { ImageView imageView = (ImageView) selectedView; } } } }