嗨,我有一个JSONObject
我已经变成了一个Array
循环遍历该数组的变量,以查看它是否存在,如果不创建一个我需要然后将其写回数组,然后返回到JSON Object
我目前已经得到但不能的继承人帽子中不太清楚如何将值写回 a JSON Object
?
public static void updateLocalDataWithObject(Context activityContext, JSONObject fullNetworkDataFromFile) throws JSONException{
JSONObject fullNetworkfile = fullNetworkDataFromFile.getJSONObject("data");
JSONObject tempUserDict = fullNetworkfile.getJSONObject("user");
String user_pref_club = tempUserDict.getString("primary_club_id");
Log.v("globals", "3.)user_pref_club = " + user_pref_club);
JSONObject userClubsDict = fullNetworkfile.getJSONObject("user_clubs");
Log.v("globals", "userClubsDict = " + userClubsDict);
if(userClubsDict.length()!= 0){
JSONArray userClubsDictKeys = new JSONArray();
userClubsDictKeys=userClubsDict.names();
ArrayList<String> stringArray = new ArrayList<String>();
for(int i = 0, count = userClubsDictKeys.length(); i< count; i++)
{
try {
JSONObject jsonObject = userClubsDictKeys.getJSONObject(i);
stringArray.add(jsonObject.toString());
}
catch (JSONException e) {
e.printStackTrace();
}
}
for(String myString : stringArray){
Log.v("globals", "myString = " + myString);
}
Log.v("globals", "ARRAY userClubsDictKeys = " + userClubsDictKeys);
String clubID = userClubsDictKeys.getString(0);
Log.v("globals", "clubID = " + clubID);
if(user_pref_club =="" || (userClubsDictKeys.getString(0) == null)) user_pref_club = clubID;
继承人什么被注销。我无法显示完整的数据,因为它很敏感,并且已被指示不要发布它。但我想做的是将 clubID 的值写入 JSONArray 中的新键值对,然后返回 JSONObject
03-01 12:00:51.269: V/globals(1085): ARRAY userClubsDictKeys = ["6496","16885"]
03-01 12:00:51.269: V/globals(1085): clubID = 6496
}