How to convert JSON string to array

后端 未结 14 883
猫巷女王i
猫巷女王i 2020-11-22 03:37

What I want to do is the following:

  1. taking JSON as input from text area in php
  2. use this input and convert it to JSON and pass it to php curl to send
相关标签:
14条回答
  • 2020-11-22 04:28
    $data = json_encode($result, true);
    
    echo $data;
    
    0 讨论(0)
  • 2020-11-22 04:29

    Use json_decode($json_string, TRUE) function to convert the JSON object to an array.

    Example:

    $json_string   = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
    
    $my_array_data = json_decode($json_string, TRUE);
    

    NOTE: The second parameter will convert decoded JSON string into an associative array.

    ===========

    Output:

    var_dump($my_array_data);
    
    array(5) {
    
        ["a"] => int(1)
        ["b"] => int(2)
        ["c"] => int(3)
        ["d"] => int(4)
        ["e"] => int(5)
    }
    
    0 讨论(0)
提交回复
热议问题