[英]How to Convert string of multiple object to in array with different keys
I have a string to multiple objects and I need to add this object in an array with different values.我有一个指向多个对象的字符串,我需要将此对象添加到具有不同值的数组中。 This data received from the cart so object can be 2,3,4...
从购物车接收到的数据,因此对象可以是 2,3,4...
exmaple:例子:
{"hidden_product_name":"productA","productId":"120","product_sku":"","quantity":"2","hidden_unit_price":"500","hidden_total":"1300","total_pr_price":"1000"},{"hidden_product_name":"productB","productId":"127","product_sku":"","quantity":"1","hidden_unit_price":"300","hidden_total":"1300","total_pr_price":"300"}
this is a full string of two objects and I want the output like this.这是两个对象的完整字符串,我想要这样的输出。
Desire output:期望输出:
[{"hidden_product_name":"productA","productId":"120","product_sku":"","quantity":"2","hidden_unit_price":"500","hidden_total":"1300","total_pr_price":"1000"},{"hidden_product_name":"productB","productId":"127","product_sku":"","quantity":"1","hidden_unit_price":"300","hidden_total":"1300","total_pr_price":"300"}]
How can I do this please help...我该怎么做,请帮助...
I found the best and easiest way to resolve this problem...我找到了解决这个问题的最好和最简单的方法......
data = '{"hidden_product_name":"productA","productId":"120","product_sku":"","quantity":"2","hidden_unit_price":"500","hidden_total":"1300","total_pr_price":"1000"},{"hidden_product_name":"productB","productId":"127","product_sku":"","quantity":"1","hidden_unit_price":"300","hidden_total":"1300","total_pr_price":"300"}';
data2 = '['+data+']';
then data2 will return:然后 data2 将返回:
[{"hidden_product_name":"productA","productId":"120","product_sku":"","quantity":"2","hidden_unit_price":"500","hidden_total":"1300","total_pr_price":"1000"},{"hidden_product_name":"productB","productId":"127","product_sku":"","quantity":"1","hidden_unit_price":"300","hidden_total":"1300","total_pr_price":"300"}]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.