我已经使用邮递员表单数据提交了此数据,那么如何从from-data数组转换为非对象JSON?
我必须尝试json_encode和json_decode,但无法将json或非对象结果放入控制器。
在CodeIgniter控制器中。
Array
(
[------WebKitFormBoundaryv6rwIfAWUgyyzeZF
Content-Disposition:_form-data;_name] => "first_name"
Janak
------WebKitFormBoundaryv6rwIfAWUgyyzeZF
Content-Disposition: form-data; name="last_name"
Kumar
------WebKitFormBoundaryv6rwIfAWUgyyzeZF
Content-Disposition: form-data; name="mobile_no"
123456789
------WebKitFormBoundaryv6rwIfAWUgyyzeZF
Content-Disposition: form-data; name="country_code"
91
------WebKitFormBoundaryv6rwIfAWUgyyzeZF
Content-Disposition: form-data; name="email_id"
test.mail@gmail.com
------WebKitFormBoundaryv6rwIfAWUgyyzeZF
Content-Disposition: form-data; name="password"
123456
------WebKitFormBoundaryv6rwIfAWUgyyzeZF
Content-Disposition: form-data; name="device_token"
123HFDT3434
------WebKitFormBoundaryv6rwIfAWUgyyzeZF
Content-Disposition: form-data; name="device_type"
2
------WebKitFormBoundaryv6rwIfAWUgyyzeZF
Content-Disposition: form-data; name="agency_name"
google
------WebKitFormBoundaryv6rwIfAWUgyyzeZF
)
答案 0 :(得分:0)
这是你的追求吗?
<?php
$content = <<<OUT
------WebKitFormBoundaryv6rwIfAWUgyyzeZF
Content-Disposition: form-data; name="last_name"
Kumar
------WebKitFormBoundaryv6rwIfAWUgyyzeZF
Content-Disposition: form-data; name="mobile_no"
123456789
------WebKitFormBoundaryv6rwIfAWUgyyzeZF
Content-Disposition: form-data; name="country_code"
91
------WebKitFormBoundaryv6rwIfAWUgyyzeZF
Content-Disposition: form-data; name="email_id"
test.mail@gmail.com'
OUT;
$clean = str_replace("\n",'',$content);
$parts = array_filter(explode('------',$clean));
$array = array();
foreach ($parts as $row){
$parts2 = explode('name="',$row);
$parts3 = explode('"',$parts2[1]);
$array[$parts3[0]] = $parts3[1];
}
echo json_encode($array);
?>
我对您的Array演示文稿有疑问,因为实际上"first_name"
是值,所以我不确定您是否正确输出了数据,但请告诉我。