Returning JSON from a PHP Script

前端 未结 18 1450
南方客
南方客 2020-11-21 04:59

I want to return JSON from a PHP script.

Do I just echo the result? Do I have to set the Content-Type header?

18条回答
  •  灰色年华
    2020-11-21 05:32

    This is a simple PHP script to return male female and user id as json value will be any random value as you call the script json.php .

    Hope this help thanks

    user_id = rand(0, 10);
    $myObj->male = rand(0, 5);
    $myObj->female = rand(0, 5);
    $myJSON = json_encode($myObj);
    echo $myJSON;
    ?>
    

提交回复
热议问题