Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php上循环抛出json时出现的问题_Php_Json - Fatal编程技术网

在php上循环抛出json时出现的问题

在php上循环抛出json时出现的问题,php,json,Php,Json,这让我快发疯了 我试图循环抛出一个特定的json: 我试着用 json_encode->抛出警告:curl_close()期望参数1是资源,给定null json_decode->显示相同的文本 $json->{“SKU”}和$json->SKU显示相同的文本 我尝试用不同的网站验证json,所有人都说json是正确的 我只想取这个值SKU、价格、特价(包含所有内容)和数量 [{ "SKU": "118075", "BrandName": "DIVIDED", "CategoryName": "

这让我快发疯了

我试图循环抛出一个特定的json:

我试着用

json_encode->抛出警告:curl_close()期望参数1是资源,给定null

json_decode->显示相同的文本

$json->{“SKU”}和$json->SKU显示相同的文本

我尝试用不同的网站验证json,所有人都说json是正确的

我只想取这个值SKU、价格、特价(包含所有内容)和数量

[{
"SKU": "118075",
"BrandName": "DIVIDED",
"CategoryName": "Correas",
"Categories": [{
    "Id": "423",
    "CategoryName": "Moda",
    "LevelDepth": "2",
    "Parent": null
}, {
    "Id": "960",
    "CategoryName": "Accesorios de Mujer",
    "LevelDepth": "3",
    "Parent": "Moda"
}],
"Name": "Divided correa Carrie",
"Description": "a",
"DescriptionShort": "v",
"MetaDescription": "Correa Divided Carrie en presentaci\u00f3n de tres colores.",
"MetaTitle": "Divided Correa Carrie",
"IsPublished": "1",
"PackageWeight": "1.000000",
"Price": 39.9,
"FinalPrice": 16.3,
"SpecialPrice": {
    "StartDate": "2014-11-21 06:00:00",
    "EndDate": "2017-12-31 23:59:00",
    "Reduction": "20.000000",
    "ReductionType": "amount"
},
"Quantity": "39",
"DateAdd": "2015-09-24 11:26:08",
"DateUpd": "2016-10-12 12:51:13",
"Images": [{
    "Id": "77",
    "Cover": "1",
    "Legend": "Divided correa Carrie",
    "url": "https:\/\/www.google.com.pe\/img\/p\/7\/7\/77.jpg"
}, {
    "Id": "78",
    "Cover": "0",
    "Legend": "Divided correa Carrie",
    "url": "https:\/\/www.google.com.pe\/img\/p\/7\/8\/78.jpg"
}, {
    "Id": "79",
    "Cover": "0",
    "Legend": "Divided correa Carrie",
    "url": "https:\/\/www.google.com.pe\/img\/p\/7\/9\/79.jpg"
}],
"FlatVariations": [{
    "SKU": "001503280",
    "Price": 39.9,
    "FinalPrice": 16.3,
    "Default": "1",
    "IdImage": "77",
    "Attributes": [{
        "Name": "Color",
        "Value": "Naranja"
    }]
}, {
    "SKU": "001503281",
    "Price": 39.9,
    "FinalPrice": 39.9,
    "Default": "0",
    "IdImage": "78",
    "Attributes": [{
        "Name": "Color",
        "Value": "Blanco"
    }]
}, {
    "SKU": "001503282",
    "Price": 39.9,
    "FinalPrice": 39.9,
    "Default": "0",
    "IdImage": "79",
    "Attributes": [{
        "Name": "Color",
        "Value": "Negro"
    }]
}]
}]


非常感谢您提供的任何提示(我已经尝试了堆栈上的几乎所有答案)

我确信您可以通过以下方式完成:

<?php
        //Enter your code here, enjoy!
$text = <<<EOT
[{
    "SKU": "118075",
    "BrandName": "DIVIDED",
    "CategoryName": "Correas",
    "Categories": [{
        "Id": "423",
        "CategoryName": "Moda",
        "LevelDepth": "2",
        "Parent": null
    }, {
        "Id": "960",
        "CategoryName": "Accesorios de Mujer",
        "LevelDepth": "3",
        "Parent": "Moda"
    }],
    "Name": "Divided correa Carrie",
    "Description": "a",
    "DescriptionShort": "v",
    "MetaDescription": "Correa Divided Carrie en presentaci\u00f3n de tres colores.",
    "MetaTitle": "Divided Correa Carrie",
    "IsPublished": "1",
    "PackageWeight": "1.000000",
    "Price": 39.9,
    "FinalPrice": 16.3,
    "SpecialPrice": {
        "StartDate": "2014-11-21 06:00:00",
        "EndDate": "2017-12-31 23:59:00",
        "Reduction": "20.000000",
        "ReductionType": "amount"
    },
    "Quantity": "39",
    "DateAdd": "2015-09-24 11:26:08",
    "DateUpd": "2016-10-12 12:51:13",
    "Images": [{
        "Id": "77",
        "Cover": "1",
        "Legend": "Divided correa Carrie",
        "url": "https:\/\/www.google.com.pe\/img\/p\/7\/7\/77.jpg"
    }, {
        "Id": "78",
        "Cover": "0",
        "Legend": "Divided correa Carrie",
        "url": "https:\/\/www.google.com.pe\/img\/p\/7\/8\/78.jpg"
    }, {
        "Id": "79",
        "Cover": "0",
        "Legend": "Divided correa Carrie",
        "url": "https:\/\/www.google.com.pe\/img\/p\/7\/9\/79.jpg"
    }],
    "FlatVariations": [{
        "SKU": "001503280",
        "Price": 39.9,
        "FinalPrice": 16.3,
        "Default": "1",
        "IdImage": "77",
        "Attributes": [{
            "Name": "Color",
            "Value": "Naranja"
        }]
    }, {
        "SKU": "001503281",
        "Price": 39.9,
        "FinalPrice": 39.9,
        "Default": "0",
        "IdImage": "78",
        "Attributes": [{
            "Name": "Color",
            "Value": "Blanco"
        }]
    }, {
        "SKU": "001503282",
        "Price": 39.9,
        "FinalPrice": 39.9,
        "Default": "0",
        "IdImage": "79",
        "Attributes": [{
            "Name": "Color",
            "Value": "Negro"
        }]
    }]
}]
EOT;

$decoded = json_decode($text);

# Index 0 because is an array
var_dump($decoded[0]->SKU);

我很确定您可以通过以下方式完成:

<?php
        //Enter your code here, enjoy!
$text = <<<EOT
[{
    "SKU": "118075",
    "BrandName": "DIVIDED",
    "CategoryName": "Correas",
    "Categories": [{
        "Id": "423",
        "CategoryName": "Moda",
        "LevelDepth": "2",
        "Parent": null
    }, {
        "Id": "960",
        "CategoryName": "Accesorios de Mujer",
        "LevelDepth": "3",
        "Parent": "Moda"
    }],
    "Name": "Divided correa Carrie",
    "Description": "a",
    "DescriptionShort": "v",
    "MetaDescription": "Correa Divided Carrie en presentaci\u00f3n de tres colores.",
    "MetaTitle": "Divided Correa Carrie",
    "IsPublished": "1",
    "PackageWeight": "1.000000",
    "Price": 39.9,
    "FinalPrice": 16.3,
    "SpecialPrice": {
        "StartDate": "2014-11-21 06:00:00",
        "EndDate": "2017-12-31 23:59:00",
        "Reduction": "20.000000",
        "ReductionType": "amount"
    },
    "Quantity": "39",
    "DateAdd": "2015-09-24 11:26:08",
    "DateUpd": "2016-10-12 12:51:13",
    "Images": [{
        "Id": "77",
        "Cover": "1",
        "Legend": "Divided correa Carrie",
        "url": "https:\/\/www.google.com.pe\/img\/p\/7\/7\/77.jpg"
    }, {
        "Id": "78",
        "Cover": "0",
        "Legend": "Divided correa Carrie",
        "url": "https:\/\/www.google.com.pe\/img\/p\/7\/8\/78.jpg"
    }, {
        "Id": "79",
        "Cover": "0",
        "Legend": "Divided correa Carrie",
        "url": "https:\/\/www.google.com.pe\/img\/p\/7\/9\/79.jpg"
    }],
    "FlatVariations": [{
        "SKU": "001503280",
        "Price": 39.9,
        "FinalPrice": 16.3,
        "Default": "1",
        "IdImage": "77",
        "Attributes": [{
            "Name": "Color",
            "Value": "Naranja"
        }]
    }, {
        "SKU": "001503281",
        "Price": 39.9,
        "FinalPrice": 39.9,
        "Default": "0",
        "IdImage": "78",
        "Attributes": [{
            "Name": "Color",
            "Value": "Blanco"
        }]
    }, {
        "SKU": "001503282",
        "Price": 39.9,
        "FinalPrice": 39.9,
        "Default": "0",
        "IdImage": "79",
        "Attributes": [{
            "Name": "Color",
            "Value": "Negro"
        }]
    }]
}]
EOT;

$decoded = json_decode($text);

# Index 0 because is an array
var_dump($decoded[0]->SKU);