Get value from JSON array in PHP

前端 未结 4 1333
名媛妹妹
名媛妹妹 2020-11-28 15:10

I\'m trying to get the value from this following JSON array in a PHP variable.

This is a var_dump of the array:

array(3) {
  [\"id\"]=>
  string(2         


        
相关标签:
4条回答
  • 2020-11-28 15:14

    you can convert a valid JSON string to a PHP variable with json_decode(). Note the second parameter to get an assoc array instead of the less usefull stdClass.

    $jsonData = json_decode($data[0]['json'], true);
    $header = $jsonData['Canvas']['MainObjects']['After Participation']['afterParticipationHeader'];
    
    0 讨论(0)
  • 2020-11-28 15:34

    It looks like you need to decode it. Try using: $json = json_decode($data[0]['json']);

    Let me know if this helps.

    0 讨论(0)
  • 2020-11-28 15:36

    First you have to decode your json data

    $json = json_decode($data[0]['json']);
    

    Then you can access your AfterParticipationHeader

    $json->Canvas[0]->MainObjects->{"After Participation"}->afterParticipationHeader
    
    0 讨论(0)
  • 2020-11-28 15:38

    You can decode the JSON via the json_decode function:

    $json = json_decode($data[0]['json']);
    

    Then, you'll have arrays (in the same structure) with your data.

    0 讨论(0)
提交回复
热议问题