2016-09-27 89 views
-4

此請求的格式是什麼?這是什麼格式?

「CUSTOMER_ID = 5米&製品%5B0%5D%5Barticle_id%5D = 4099 &製品%5B0%5D%5Bquantity%5D = 1米&製品%5B0%5D%5Btotal_price%5D = 0」

是有一種方法可以自動將JSON或普通文本轉換爲這種格式?

+0

這是一個網址的一部分?像www.sampleurl.com?customer_id=5&products%5B0 ... – Yannjoel

+1

這看起來像一個URL編碼。解碼結果如下:'''customer_id = 5&products [0] [article_id] = 4099&products [0] [quantity] = 1&products [0] [total_price] = 0'''。從json轉換應該是顯而易見的。另外,請閱讀關於提問的幫助部分... –

+0

如果您使用js,您可以將json對象轉換爲字符串,並將「:」替換爲「=」,「,」替換爲「&」,然後移除「{」和「}」然後url編碼。 – mkysoft

回答

0

此請求字符串似乎是爲URL/URI編碼的。

您可以使用decodeURIComponent查看原始字符串。例如:

var s = "customer_id=5&products%5B0%5D%5Barticle_id%5D=4099&products%5B0%5D%5Bquantity%5D=1&products%5B0%5D%5Btotal_price%5D=0"; 
var original = decodeURIComponent(s); 

這將產生以下

"customer_id=5&products[0][article_id]=4099&products[0][quantity]=1&products[0][total_price]=0" 

要轉換爲這種格式,你可以使用原始字符串稱爲encodeURIComponent反函數。