Merge JSON Object with same “key” and add their “value” using JavaScript

后端 未结 5 1996
误落风尘
误落风尘 2021-02-06 19:07

My JSON looks like this

{\"rows\":[
    {\"key\":[\"zeit.de\"],\"value\":98},
    {\"key\":[\"google.com\"],\"value\":49},
    {\"key\":[\"spiegel.de\"],\"value\         


        
5条回答
  •  逝去的感伤
    2021-02-06 19:26

    JSON look like below: 2 scenario Url is common When pass the role -id

    1. role- id/name has admin:

      [{"Key":"value1"},{"key":"value2"},{"key":"value3"}]
      
    2. role- id/name has Tester

      [{"Key":"value1"},{"key":"value3"}]
      

    no key:value2 is there for Tester

    For example:

    Global variable string a, b;

    wants to take all of the values from the key-value Pair if it has value2 and value3 from the JSON

    i.e.: admin go for a="both"

    check Tester if it has only value3 then b="single"

提交回复
热议问题