我试图访问所有成员,JSON对象无法全部访问它们,我从数据库中检索到15个关键数据,它在JSON对象中无法将其检索到String对象中。仅有8个是无法访问对象和其他对象。
JSONObject jsonObject = new JSONObject(response);
JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY);
JSONObject userData = result.getJSONObject(0);
Toast.makeText(context,"json object "+jsonObject,Toast.LENGTH_LONG).show();
Toast.makeText(context,"result "+result,Toast.LENGTH_LONG).show();
Toast.makeText(context,"userdata "+userData,Toast.LENGTH_LONG).show();
username =userData.getString(Config.KEY_USERNNAME);
email = userData.getString(Config.KEY_EMAIL);
fathername=userData.getString(Config.KEY_FATHERNAME);
mothername=userData.getString(Config.KEY_MOTHERNAME);
studentcontact=userData.getString(Config.KEY_STUDENTCONTACT);
parentcontact=userData.getString(Config.KEY_PARENTCONTACT);
stu_class=userData.getString(Config.KEY_CLASS);
tuition=userData.getString(Config.KEY_TUITION);
Toast.makeText(context,tuition,Toast.LENGTH_LONG).show();
address=userData.getString(Config.KEY_ADDRESS);
Toast.makeText(context,address,Toast.LENGTH_LONG).show();
fees=userData.getString(Config.KEY_FEES);
feesstatus=userData.getString(Config.KEY_FEESSTATUS);
rankbatch=userData.getString(Config.KEY_RANKBATCH);
ranktuition=userData.getString(Config.KEY_RANKTUITION);
teacherremark=userData.getString(Config.KEY_TEACHERREMARK);
joindate=userData.getString(Config.KEY_JOINDATE);
dob=userData.getString(Config.KEY_DOB);
Toast.makeText(context,dob,Toast.LENGTH_LONG).show();
getJSON对象返回我
{
"result":[
{
"username":"Akshay Kumar",
"email":"example@example.com",
"fathername":"FatherName",
"mothername":"MotherName ",
"studentcontact":"9999999999",
"parentcontact":"9999999999",
"class":"BTECH",
"tuition":"Computer",
"address":"Address",
"fees":"5000",
"feesstatus":"paid",
"rankbatch":"2",
"ranktuition":"2",
"teacherremark":"Good Student",
"joindate":"2016-07-04",
"dob":"2016-01-01"
}
]
}
这是我的配置类
public class Config {
public static final String DATA_URL = "http://someurl.com/xyz.php";
public static final String KEY_USERNNAME = "username";
public static final String KEY_EMAIL = "email";
public static final String KEY_FATHERNAME ="fathername";
public static final String KEY_MOTHERNAME = "mothername";
public static final String KEY_STUDENTCONTACT ="studentcontact";
public static final String KEY_PARENTCONTACT = "parentcontact";
public static final String KEY_CLASS="class";
public static final String KEY_TUITION ="tuition";
public static final String KEY_ADDRESS="addresss";
public static final String KEY_FEES="fees";
public static final String KEY_FEESSTATUS="feesstatus";
public static final String KEY_RANKBATCH="rankbatch";
public static final String KEY_RANKTUITION="ranktuition";
public static final String KEY_TEACHERREMARK="teacherremark";
public static final String KEY_JOINDATE="joindate";
public static final String KEY_DOB="dob";
public static final String JSON_ARRAY = "result";
}
这是我的代码,在这里显示jsonObject的上面3个Toast,结果和userData显示从数据库中检索到的整个数据。学费下面的Toast也显示学费字符串的数据但是在学费字符串之后没有检索到数据它显示为空。 现在我没有得到如何从JSON对象中检索我的其他数据。