如何在PHP中处理JSON? [英] How to process JSON in PHP?

查看:116
本文介绍了如何在PHP中处理JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是异步发送到我的php页面的JSON.本质上,这是一个产品列表,它将插入到我的mySQL数据库中.

Here is the JSON which is sent asynchronously to my php page. It is essentially a product list, which will be inserted into my mySQL database.

我的问题是用PHP解码JSON.我可以使用``eval''函数在js中做到这一点,但是在PHP中,我的努力导致了一系列复杂的爆炸和内爆函数.

My issue is decoding the JSON in PHP. I can do this fine in js with the 'eval' function, but in PHP my efforts have resulted in a complicated series of explode and implode functions.

{
    "Product": [
        {
            "Product_Title": "Cloth",
            "Product_Description": "Here is cloth",
            "Price": "100",
            "Category_ID": "1"
        },
        {
            "Product_Title": "Cloth",
            "Product_Description": "Here is cloth",
            "Price": "100",
            "Category_ID": "1"
        },
        {
            "Product_Title": "Cloth",
            "Product_Description": "Here is cloth",
            "Price": "100",
            "Category_ID": "1"
        }
    ]
}

我知道php具有内置的json_decode函数,但是在PHP文档中,它们仅显示如何处理数组.

I know php has a built in json_decode function, but in the PHP documentation they only show how to handle an array.

真的很感谢任何建议或帮助

Any advice or help is really appreciated

泰勒

推荐答案

如果您调用json_decode($data,true);,则数据将为:

If you call json_decode($data,true);, your data will be:

Array(
    "Product"=>Array(
        Array(
            "Product_Title"=>"Cloth",
            "Product_Description"=>"Here is cloth",
            "Price"=>"100",
            "Category_ID"=>"1"
        ),
        Array(
.............
        )
    )
);

这有什么问题?

这篇关于如何在PHP中处理JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆