使用MySQL数据库在PHP中以下嵌套数组网络服务


"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"
         }
      ]
   ]

即。我想要数据和产品之后。

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

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

相关内容

  • 没有找到相关文章

最新更新