简体   繁体   中英

PHP getting value inside curly braces

I have this so far:

$response = json_decode($response, true);
foreach ($response['result'] as $loc)
{
        echo "" . $loc['metadata'] ."\n";
};

This outputs:

{   
    "name":"Bob",
    "image":"test.png",
    "description":"Test",
    "edition":"1",
    "size":"50x50",
    "type":"G",
    "location":"900,0",
    "attributes":[
        {
            "trait_type":"Location",
            "value":"900,0"
        },
        {
            "trait_type":"Size",
            "value":"50x50"},
        {
            "trait_type":"Type",
            "value":"G"
        }
    ]
}

How do I get the value of "location"?

EDIT:

foreach ($response['result'] as $loc) {
    foreach ($loc['metadata'] as $lo) {
        $lo = json_decode($lo, true);
        echo "" .$lo['location'] . "\n";
    };
    //echo "" . $loc['metadata'] ."\n";
};

you need to json decode the inner JSONString which exists in $loc['metadata']

foreach ($response['result'] as $loc) {
    $meta = json_decode($loc['metadata']);
    echo $meta['location'] ."\n";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM