在php中选择单独的列json


Select individual column json in php

{
    "responseData": {
        "results": [
            {
                "title": "sobig",
                "titleNoFormatting": "test",
            },
            {
                "title": "test 2 ",
                "titleNoFormatting": "test 2sd",
            },
            {
                "title": "asdasdasda",
                "titleNoFormatting": "asdasdasd",
            },
            {
                "title": "A Warming",
                "titleNoFormatting": "A Warming",
            }
         .
         . 
         . 
         . 
            {
                "title": "last thing",
                "titleNoFormatting": "sada",
            }
        ],

我有这样的json文件。

for($i=$veri1; $i <= $veri2; $i++) {
        $uri    = "http://test.com/json/".$i."/0";
        $json   = json_decode(file_get_contents($uri));
        if($json->data->price >= $nakit && $json->data->odds >= $oran)
        {

我从另一个json文件中正确地获得了一些数据。

我想从第一个json代码,if "title" == "sobig"获取数据。我怎么能做到呢?

$json->responseData->results->title == sobig不工作。如果title这么大

我怎么能得到数据呢?
$json= json_decode($response, true); 
foreach ($json['responseData']['results'] as $key => $value) {
    if ($value == 'sobig') {
        // found it
    }
}

试试这个例子,看看是否可以解决您的问题。

<?php
$json = '{ "responseData": {
               "result" : [
                   { "title": "sobig" , "titleNo":"test"},
                   { "title": "loco" , "titleNo":"test"},
                   { "title": "tom" , "titleNo":"test"}
               ]
}}';
    $jsonDecoded = json_decode($json);

    foreach ($jsonDecoded->responseData->result as $key => $value) {
         var_dump($value); echo '<br>';
        if($value->title == 'sobig'){
            echo "we did it!!";
            echo "<br>";
        }
        }
?>

我放置了几个var转储,这样您就可以看到对象的结构以及为什么需要使用foreach