我有以下的JSON数组我使用POST方法将其发送到后端:错误的JSON数组在Java中,并添加回URL削减
{"images":
[["https:\/\/storage.googleapis.com\/shelf-prove\/test1.jpg",
"https:\/\/storage.googleapis.com\/shelf-prove\/test2.jpg",
"https:\/\/storage.googleapis.com\/shelf-prove\/test3.jpg",
"https:\/\/storage.googleapis.com\/shelf-prove\/test5.jpg"]],
"skus":["
{\"id\":5179846254657536,\"coordinates\":\"137,447,692,438,690,610,140,617\",\"sku\":\"Biscotti\"}",
"{\"id\":5656058538229760,\"coordinates\":\"0,116,303,104,310,264,2,282\",\"sku\":\"Riso\"}",
"{\"id\":5765606242516992,\"coordinates\":\"140,614,675,610,673,751,145,755\",\"sku\":\"Succo\"}"],
"percentage":"33",
"model":5682617542246400,
"shelf":5660980839186432
}
在Java中我试图把它作为JSON阵列以下代码:
imagesToProcess = json.getJSONArray("images");
for(int i = 0; i < imagesToProcess.length(); i++){
String src="";
src = imagesToProcess.getString(i); }
的问题是,在Java我看到数组的值如下:
[["https:\/\/storage.googleapis.com\/shelf-prove\/test1.jpg","https:\/\/storage.googleapis.com\/shelf-prove\/test2.jpg","https:\/\/storage.googleapis.com\/shelf-prove\/test3.jpg","https:\/\/storage.googleapis.com\/shelf-prove\/test5.jpg"]]
和for循环,每个lement的值是这样的:
[["https:\/\/storage.googleapis.com\/shelf-prove\/test1.jpg","https:\/\/storage.googleapis.com\/shelf-prove\/test2.jpg","https:\/\/storage.googleapis.com\/shelf-prove\/test3.jpg","https:\/\/storage.googleapis.com\/shelf-prove\/test5.jpg"]]
我不知道是什么问题!
对于添加反斜杠。我在Android中看到了这个标准的JSON API。据说他们使用这种逻辑能够在GET请求中使用这些值。如果这确实是个问题,或者使用相同的API来解码,则可以使用其他API。对于数组,因为你的json.getJSONArray(“images”);'但是在你的JSON中没有看到任何'images'键,这个答案很复杂。您可能需要发布[mcve]以查找未知数 – AxelH
我已更新JSON – Majico
您有一个数组数组,因此您想要的数组实际上位于imagesToProcess [0]中。但是这应该会输出一个'[“https:\/\/...'不是'[[”https:\/\/...' – AxelH