使用mysql数据库在php中获取以下嵌套数组webservice

时间:2018-04-28 13:53:13

标签: php mysql web-services

"data":{  
   "2":{  
      "sub_category_id":"1",
      "product":[  
         {  
            "sub_category_id":"1",
            "product_id":"1",
            "product_name":"American"
         },
         {  
            "sub_category_id":"1",
            "product_id":"34",
            "product_name":"Ausi Product"
         }
      ]
   },
   "3":{  
      "sub_category_id":"2",
      "product":{  
         "2":{  
            "sub_category_id":"2",
            "product_id":"2",
            "product_name":"Canadian"
         }
      }
   }
}

我除外的结果:

"data":[  
   "2":{  
      "sub_category_id":"1",
      "product":[  
         {  
            "sub_category_id":"1",
            "product_id":"1",
            "product_name":"American"
         },
         {  
            "sub_category_id":"1",
            "product_id":"34",
            "product_name":"Ausi Product"
         }
      ]
   },
   "3":{  
      "sub_category_id":"2",
      "product":[  
         "2":{  
            "sub_category_id":"2",
            "product_id":"2",
            "product_name":"Canadian"
         }
      ]
   ]

即。我想在数据和产品之后找到[]。

1 个答案:

答案 0 :(得分:-1)

您可以指示PHP json_decode()函数将对象解析为关联数组。

$parsedJSON = json_decode($jsonString, /* $assoc = */ true)