我有一些使用ajax的请求,我想用curl调用它。 那个ajax表单数据应该是这样的
// $i starts at 0 since array index's start at 0
for($i = 0; $i < count($Obj->string); $i++)
{
echo $Obj->string[$i];
// TODO: Add your code...
}
我试着写它并且有我的代码
q:user_id(367091) {
followed_by.after(10) {
count,
page_info {
end_cursor,
has_next_page
},
nodes {
id,
is_verified,
followed_by_viewer,
requested_by_viewer,
full_name,
profile_pic_url,
username
}
}
}
我有一点困惑,填写像user_id,follow_by.after,这可以用嵌套数组写? 如何使类/对象变量/像指针一样,所以我们有数据数组和自己的值。有人请帮忙
答案 0 :(得分:1)
答案应该是这样的。
$array_post=
array(
"q" => "user_id(367091) {
followed_by.after(10) {
count,
page_info {
end_cursor,
has_next_page
},
nodes {
id,
is_verified,
followed_by_viewer,
requested_by_viewer,
full_name,
profile_pic_url,
username
}
}
}",
);
$field_string = urldecode(http_build_query($array_post));
curl_setopt($c, CURLOPT_POSTFIELDS, $field_string);
答案 1 :(得分:0)
这个怎么样?
$test = array(
'q:user_id(367091)' => array(
'followed_by.after(10)' => array(
'count' => '',
'page_info' => array(
'end_cursor' => '',
'has_next_page' => ''
),
'nodes' => array(
'id' => '',
'is_verified' => '',
'followed_by_viewer' => '',
'requested_by_viewer' => '',
'full_name' => '',
'profile_pic_url' => '',
'username' => ''
)
)
)
);
此输出看起来与您需要的类似:
print_r(json_encode($test, JSON_PRETTY_PRINT));