私はJsonArrayをStringArrayに変換しようとしていますが、Json配列から値を取得することはできません。私は以下のコードを使用しますが、resultsFollowedUsersVar.getJSONObject(i);
部分に私はエラー、私はこの問題を解決するにはどうすればよいAndroidのJsonArrayから値を取得できませんか?
Unhandled exception, org.JSON.jsonException
を取得していますか?
resultsFollowedUsers = new ArrayList<String>();
resultsFollowedAndPendingUsers = new ArrayList<String>();
resultsFollowedUsers.removeAll(resultsFollowedUsers);
resultsFollowedAndPendingUsers.removeAll(resultsFollowedAndPendingUsers);
ParseQuery<ParseObject> followedQuery = ParseQuery.getQuery("followCount");
followedQuery.whereEqualTo("userid", ParseUser.getCurrentUser().getObjectId());
followedQuery.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
for (ParseObject object : objects) {
JSONArray resultsFollowedUsersVar = object.getJSONArray("followedArray");
JSONObject json_obj = null;
for (int i = 0; i < resultsFollowedUsersVar.length(); i++){
try {
System.out.println("Check if program enters here");
System.out.println(resultsFollowedUsersVar.getJSONObject(i));
System.out.println(json_obj.toString());
json_obj = resultsFollowedUsersVar.getJSONObject(i);
resultsFollowedUsers.add(json_obj.toString());
}
catch(JSONException ex) {
ex.printStackTrace();
}
}
System.out.println(resultsFollowedUsersVar.toString());
System.out.println(resultsFollowedUsers);
JSONArray resultsFollowedAndPendingUsersVar = object.getJSONArray("followPendingArray");
JSONObject json_obj2 = null;
for(int i = 0; i < resultsFollowedAndPendingUsersVar.length(); i++){
try{
System.out.println("Check if program enters here 2");
json_obj2 = resultsFollowedAndPendingUsersVar.getJSONObject(i);
resultsFollowedAndPendingUsers.add(json_obj2.toString());
}catch(JSONException ex){
ex.printStackTrace();
}
}
}
}
reloadData();
}
});
:
System.out.println(resultsFollowedUsersVar.toString())
はログに結果を与える:
["WE27P50RyN","eG0KdMIKJd","rsnwFrkc3r","IqKNzdkVw7"]
:
:System.out.println(resultsFollowedUsersVar.getJSONObject(i))
ログに結果を与えます3210
org.json.JSONException: Value IqKNzdkVw7 at 3 of type java.lang.String cannot be converted to JSONObject
は編集:私は最終的に解決策を持って、私は間違った方法での解析から配列を取得して、私は最終的に以下のようにそれを作った:
resultsFollowedUsers = new ArrayList<String>();
resultsFollowedAndPendingUsers = new ArrayList<String>();
resultsFollowedUsers.removeAll(resultsFollowedUsers);
resultsFollowedAndPendingUsers.removeAll(resultsFollowedAndPendingUsers);
ParseQuery<ParseObject> followedQuery = ParseQuery.getQuery("followCount");
followedQuery.whereEqualTo("userid", ParseUser.getCurrentUser().getObjectId());
followedQuery.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
for (ParseObject object : objects) {
resultsFollowedUsers = (ArrayList<String>) object.get("followedArray");
resultsFollowedAndPendingUsers = (ArrayList<String>) object.get("followPendingArray");
System.out.println(resultsFollowedUsers);
System.out.println(resultsImageFiles);
}
}
reloadData();
}
});
だけでなく、あなたのJSONとスタックトレースを投稿 – SMR