How to convert JSON string to array

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

    If you are getting json string from URL using file_get_contents, then follow the steps:

    $url = "http://localhost/rest/users";  //The url from where you are getting the contents
    $response = (file_get_contents($url)); //Converting in json string
     $n = strpos($response, "[");
    $response = substr_replace($response,"",0,$n+1);
    $response = substr_replace($response, "" , -1,1);
    print_r(json_decode($response,true));
    

提交回复
热议问题