Jump to content

json string obj conversion


avvllvva

Recommended Posts

Following is my current json obj string

 

[
{"productId":"101","price":99},
{"productId":"201","price":88},
{"productId":"301","price":77},

{"productId":"101","count":3},
{"productId":"201","count":5}],
{"productId":"301","count":2}],

{"productId":"101","month":12},
{"productId":"201","month":10}],
{"productId":"301","month":09}
]

 

i want to convert it into following format

ie; grouping by product id along with their parameters together

 

[
{products:'101',parameters[99,3,12]},
{products:'201',parameters[88,5,10]},
{products:'301',parameters[77,2,09]}
]

 

 

-thanks

Link to comment
https://forums.phpfreaks.com/topic/250146-json-string-obj-conversion/
Share on other sites

Solution:

 

Instead of using this:

[
{"productId":"101","price":99},
{"productId":"201","price":88},
{"productId":"301","price":77},

{"productId":"101","count":3},
{"productId":"201","count":5}],
{"productId":"301","count":2}],

{"productId":"101","month":12},
{"productId":"201","month":10}],
{"productId":"301","month":09}
]

 

 

Use this:

[
{products:'101',parameters[99,3,12]},
{products:'201',parameters[88,5,10]},
{products:'301',parameters[77,2,09]}
]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.