如何将 JSON 以下数据转换为 application/x-www-form-urlencoded?
How to convert below JSON data to application/x-www-form-urlencoded?
我想将以下 JSON 数据转换为 x-www-form-urlencoded 格式。如何在 JavaScript 中做到这一点?或者任何在线转换器?
stripe_data: {
"type" : "card",
"billing_details" : {
"name" : "sample test",
"email" : "sampletest@gmail.com",
"phone" : "+61 76 253 4125",
"address" : {
"state" : "Melborne",
"country" : "Australia"
}
},
"card" : {
"number" : "4242424242424242",
"cvc" : "242",
"exp_month" : "01",
"exp_year" : "22"
}
}
我搜索了 google 但我没有找到针对此类数据(对象到对象)的任何解决方案。
我使用名为 qs
的 JavaScript 包解决了上述问题。
我在 Nuxt.js 工作并使用 npm 所以我通过那一点给出答案
首先使用 npm run qs
安装
然后在您的代码中导入 qs,如 import qs from 'qs'
然后在任何你想要的地方使用 qs.stringify(data)
// data - JSON format
我想将以下 JSON 数据转换为 x-www-form-urlencoded 格式。如何在 JavaScript 中做到这一点?或者任何在线转换器?
stripe_data: {
"type" : "card",
"billing_details" : {
"name" : "sample test",
"email" : "sampletest@gmail.com",
"phone" : "+61 76 253 4125",
"address" : {
"state" : "Melborne",
"country" : "Australia"
}
},
"card" : {
"number" : "4242424242424242",
"cvc" : "242",
"exp_month" : "01",
"exp_year" : "22"
}
}
我搜索了 google 但我没有找到针对此类数据(对象到对象)的任何解决方案。
我使用名为 qs
的 JavaScript 包解决了上述问题。
我在 Nuxt.js 工作并使用 npm 所以我通过那一点给出答案
首先使用 npm run qs
安装
然后在您的代码中导入 qs,如 import qs from 'qs'
然后在任何你想要的地方使用 qs.stringify(data)
// data - JSON format