How to convert JSON string to array

后端 未结 14 880
猫巷女王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:12

    You can change a string to JSON as follows and you can also trim, strip on string if wanted,

    $str     = '[{"id":1, "value":"Comfort Stretch"}]';
    //here is JSON object
    $filters = json_decode($str);
    
    foreach($filters as $obj){
       $filter_id[] = $obj->id;
    }
    
    //here is your array from that JSON
    $filter_id;
    

提交回复
热议问题