Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.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,我正在开发flipkart新产品api,实际上我使用数组位置从api中获得了所有值,但我希望在键值为true时获得值 {"productBaseInfoV1":{"productId":"MOBDQAYCV9JTWHGG","title":"Videocon Dost V1615","productDescription":"","imageUrls":{"400x400":"http://img.fkcdn.com/image/mobile/h/g/g/videocon-dost-v1615-

我正在开发flipkart新产品api,实际上我使用数组位置从api中获得了所有值,但我希望在键值为true时获得值

{"productBaseInfoV1":{"productId":"MOBDQAYCV9JTWHGG","title":"Videocon Dost V1615","productDescription":"","imageUrls":{"400x400":"http://img.fkcdn.com/image/mobile/h/g/g/videocon-dost-v1615-400x400-imadqb7k6hzdgyd8.jpeg","200x200":"http://img.fkcdn.com/image/mobile/h/g/g/videocon-dost-v1615-200x200-imadqb7k6hzdgyd8.jpeg","unknown":"http://img.fkcdn.com/image/mobile/h/g/g/videocon-dost-v1615-original-imadqb7k6hzdgyd8.jpeg","800x800":"http://img.fkcdn.com/image/mobile/h/g/g/videocon-dost-v1615-800x800-imadqb7k6hzdgyd8.jpeg"},"productFamily":null,"maximumRetailPrice":{"amount":0.0,"currency":"INR"},"flipkartSellingPrice":{"amount":0.0,"currency":"INR"},"flipkartSpecialPrice":{"amount":0.0,"currency":"INR"},"productUrl":"http://dl.flipkart.com/dl/videocon-dost-v1615/p/itmegtdatuc7w9tz?pid=MOBDQAYCV9JTWHGG&affid=infoadspl","productBrand":"Videocon","inStock":false,"codAvailable":true,"discountPercentage":0.0,"offers":[],"categoryPath":"[[{\"node_id\":20001,\"node_name\":\"FLIPKART_TREE\"},{\"node_id\":20143,\"node_name\":\"Mobiles\"},{\"node_id\":20144,\"node_name\":\"Handsets\"}]]","styleCode":null,"attributes":{"size":"","color":"Silver","storage":"","sizeUnit":"","displaySize":""}},"productShippingInfoV1":{"shippingCharges":{"amount":0.0,"currency":"INR"},"estimatedDeliveryTime":null,"sellerName":null,"sellerAverageRating":null,"sellerNoOfRatings":0,"sellerNoOfReviews":0},"categorySpecificInfoV1":{"keySpecs":["Primary Camera: 1.3 megapixel","Sim Type: Dual Sim"],"detailedSpecs":[],"specificationList":[{"key":"GENERAL FEATURES","values":[{"key":"In the Box","value":["Mobile handset, Battery, Warranty card, Charger, Handsfree, USB Cable, User Manual"]},{"key":"Brand","value":["Videocon"]},{"key":"Model Name","value":["Dost V1615"]},{"key":"SIM Size","value":["Full Size SIM"]},{"key":"SIM Type","value":["Dual Sim"]},{"key":"Touch Screen","value":["No"]},{"key":"Handset Color","value":["Silver"]}]},{"key":"Display","values":[{"key":"Size","value":["3.5 inch"]},{"key":"Resolution","value":["QVGA, 320 x 240 Pixels"]}]},{"key":"Camera","values":[{"key":"Rear Camera","value":["Yes, 1.3 MP"]}]},{"key":"Battery","values":[{"key":"Type","value":["Li-Ion, 1800 mAh"]}]},{"key":"Memory and Storage","values":[{"key":"Expandable Memory","value":["microSD, upto 16 GB"]}]},{"key":"Internet & Connectivity","values":[{"key":"USB Connectivity","value":["Yes"]},{"key":"Audio Jack","value":["3.5 mm"]}]},{"key":"Warranty","values":[{"key":"Warranty Summary","value":["1 Year Standard Manufacturer Warranty for Mobile Handsets and 6 Months for in-box Accessories"]},{"key":"Warranty Service Type","value":["Customer needs to call/visit nearest Service centre since product comes with 1 Year Manufacturer warranty"]}]}],"booksInfo":{"language":null,"binding":null,"pages":null,"publisher":null,"year":0,"authors":[]},"lifeStyleInfo":{"sleeve":null,"neck":null,"idealFor":null}}}
这里是演示供参考

这是我的密码

<?php
$url='http://myperfectprice.com/flipkart.json';
$decode=file_get_contents($url);        
$product = json_decode($decode,true);
$keySpecs = $product['categorySpecificInfoV1']['keySpecs'][0];
$Brand = $product['categorySpecificInfoV1']['specificationList'][0] ['values'][1]['value'][0];
$model = $product['categorySpecificInfoV1']['specificationList'][0]['values'][2]['value'][0];
$sim_size = $product['categorySpecificInfoV1']['specificationList'][0]['values'][3]['value'][0];
$sim_type = $product['categorySpecificInfoV1']['specificationList'][0]['values'][4]['value'][0];

?>
keySpecs=<?=$keySpecs; ?><br />
Brand=<?=$Brand; ?><br />
Model=<?=$model; ?><br />
Sim_size=<?=$sim_size; ?><br />

键规范=
品牌=
模型=
Sim_大小=

我不太明白这个问题,也许像这样的方法行得通

if ( $product['categorySpecificInfoV1']['specificationList']['key'] == 'GENERAL FEATURES'){
    //get the specificationList
}
使用数组()中的
在数组中查找
“常规功能”
,并在单独的数组中分配
规格列表
,如果存在

<?php
$url='http://myperfectprice.com/flipkart.json';
$decode=file_get_contents($url);        
$product = json_decode($decode,true);
if(in_array('GENERAL FEATURES',$product['categorySpecificInfoV1']['specificationList'][0]))
{
    $specificationList = $product['categorySpecificInfoV1']['specificationList'];
}
echo "<pre>"; print_r($specificationList);
?>


你能至少举个例子说明你想要什么吗?我需要json的规范列表,如果“关键”“一般功能”真的很好:)很高兴能帮助你@普拉巴斯曼达尔