【发布时间】:2019-09-17 15:35:55
【问题描述】:
我正在更新 JSONArray 内的 JSONObject 中的值,当更改所有 JSONArray 中的值时。有人知道为什么吗?
public static void uploadMediaWithThumbnail( final LeagueActivity.UploadingCallback call,
final long leagueId,
final JSONArray information, final JsonHttpResponseHandler handler) {
final AtomicInteger receivedCount = new AtomicInteger();
receivedCount.set(0);
call.progressCall(10);
getMediaUploadUrl(leagueId, information, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
try {
call.progressCall(20);
final JSONArray allData = response.getJSONArray("upload_data");
AsyncHttpClient[] clients = new AsyncHttpClient[allData.length()*2];
JSONArray jarr = information;
for (int i = 0; i < allData.length(); i++ ) {
final String uploadUrl = allData.getJSONObject(i).getString("content_url");
final String previewUrl = allData.getJSONObject(i).getString("preview_url");
jarr.getJSONObject(i).put("content", uploadUrl);
jarr.getJSONObject(i).put("preview", previewUrl);
}
final JSONArray newInfo = shallowCopy(jarr);
Log.d("Log1", newInfo.getJSONObject(1).getString("content"));
Log.d("Log2", newInfo.getJSONObject(0).getString("content"));
记录 Log1 和 Log2 时,它们包含相同的链接
信息是这样的数据[{"type":"video","format":"mp4","preview_format":"jpg"}, {"type":"video","format":"mp4","preview_format":"jpg"}]
AllData 是从 REST HTTP 调用接收的信息,与信息具有相同的长度
【问题讨论】:
-
信息是一个带有数据的 JSONArray
-
请发布完整代码@David Vittori
-
似乎
information与当前形式的allData是多余的。如果information是在本地维护的,则没有理由在 JSON 中处理它。它可以是普通的数据结构,如 List 或 Array。 -
好吧,所有数据都从服务器中检索出来,信息将被发送出去。
-
您确定
alldata和information具有相同的长度,因为您在一个循环中解析两者。