我正在使用使用 php 的 rest-api。有人可以告诉我如何使用 php 表示以下 JSON 格式吗?其余 API 需要此格式才能执行筛选。
--data-urlencode 'where={"post":{"__type":"Pointer","className":"Post","objectId":"8TOXdXf3tz"}}' ''
您可以使用
PHP创建数组,然后使用json_encode函数创建JSON格式。
json_decode该
字符串表示将产生的确切数组,但是yip和数组数组...
$a = json_decode('{"post":{"__type":"Pointer","className":"Post","objectId":"8TOXdXf3tz"}}',true);
结果:
array(1) {
["post"] => array(3) {
["__type"] => string(7) "Pointer"
["className"] => string(4) "Post"
["objectId"] => string(10) "8TOXdXf3tz"
}
}
所以在 PHP 中写成数组:
$thing = array(
"post" => array(
"__Type" => "Pointer",
"className" => "Post",
"objectId" =>> "9878076"
);
);
然后json_encode会重新创建 json...