我想在邮递员中对我的 API 做出响应...但是当我发送邮递员的原始正文时 我面临数组到字符串转换错误
错误异常(E_NOTICE) 数组到字符串的转换
这是我的原料
{
"account_type": "real",
"address": "12131",
"card_bank": "",
"city": {
"id": 436,
"name": "مشهد",
"state_id": 11,
"state_name": "خراسان رضوی"
},
"code_melli": "",
"email": "",
"family": "اسداله پور",
"id": 171,
"mobile": "0911111111",
"name": "مهدی",
"phone": "",
"role": "usual",
"card": [
{
"count": 1,
"id": 2,
"id_product": 267,
"productM": null,
"seller": null,
"id_seller": 0,
"totalPrice": "97500"
},
{
"count": 1,
"id": 3,
"id_product": 696,
"productM": null,
"seller": null,
"id_seller": 0,
"totalPrice": "115000"
}
],
"state": {
"id": 11,
"name": "خراسان رضوی"
}
}
这是我的网络服务 关于这条路线
public function ChangeInformation(Request $request)
{
$validator = Validator::make(
$request->all(),
[
'name' => 'required',
'family' => 'required',
'mobile' => 'required',
],
[
'name.required' => 'لطفا نام خود را وارد کنید',
'family.required' => 'لطفا نام خانوادگی خود را وارد کنید',
'mobile.required' => 'لطفا موبایل خود را وارد کنید',
]);
if ($validator->fails()) {
self::$result_json['error'] = 1;
self::$result_json['error_code'] = 1;
self::$result_json['msg'] = $validator->messages()->first();
}
else{
$user = DB::table('user_app')
->where('id', $request->get('token'))
->first();
$input = $request->except('img');
/*if ($request->hasFile('img')) {
$file_param = $request->file('img');
$fileName = $file_param->getClientOriginalName();
$fileName = substr($fileName, 0, strrpos($fileName, '.'));
$fileName = str_replace(' ', '', $fileName);
$Random_Number = rand(0, 9999);
$name_file_new = $fileName . '-' . $Random_Number . '.' . $file_param->getClientOriginalExtension();
//$thumb_img = Image::make($file->getRealPath())->resize(100, 100);
$destinationPath = 'uploads/avatars/';
$file_param->move($destinationPath, $name_file_new);
$path_file = 'uploads/avatars/' . $name_file_new;
$input['img'] = $path_file;
}
else {
self::$result_json['error'] = 1;
self::$result_json['error_code'] = 1;
self::$result_json['msg'] = 'تصویر نادرست است .';
}*/
DB::table('user_app')
->where('id',$user->id)
->update($input);
$city = DB::table('cities')
->where('id', $input['shahr'])
->first();
$state = DB::table('state')
->where('id', $input['ostan'])
->first();
$user_data = DB::table('user_app')
->where('id',$user->id)
->select('account_type', 'address','email','card_bank', 'shahr as city',
'family', 'id', 'mobile', 'name', 'img', 'phone', 'role', 'ostan as state', 'zip_code')
->first();
$user_data->city = $city;
$user_data->state = $state;
self::$result_json['success'] = 1;
self::$result_json['user_data'] = $user_data;
}
当我在 form_data 中发送数据时它可以工作,但当我发送数据时它不能在 raw 中工作
你需要使用“json_encode()函数”将你的关联数组转换为json对象格式,它是字符串,邮递员无法读取数组,我希望这个能做到