Hỏi đáp

Chia sẻ kiến thức, cùng nhau phát triển

Nhóm các list có key trùng nhau

09:06 17-01-2019 356 lượt xem 0 bình luận

Chào mọi người mình có một json 

[{"seller_id":3,"item":{"product_id":4,"amount":1,"id":9}},{"seller_id":1,"item":{"product_id":1,"amount":2,"id":10}},{"seller_id":3,"item":{"product_id":3,"amount":2,"id":11}},{"seller_id":1,"item":{"product_id":2,"amount":2,"id":12}}]

mình muốn nhóm lại nghĩa là các seller trùng nhau sẽ nhóm cái item lại 

kết quả trả về giống như:

[{"seller_id":3,"list_item":[{"product_id":4,"amount":1,"id":9},{"product_id":3,"amount":2,"id":11}]},{"seller_id":1,"list_item":[{"product_id":1,"amount":2,"id":10},{"product_id":1,"amount":2,"id":10},{"product_id":2,"amount":2,"id":12}]}]

ai có ý tưởng j ko ạ 

Bình luận

Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam.

Đăng nhập

Câu hỏi mới nhất