[英]Illegal string offset error in PHP
我将这些对象发送到服务器以获取记录并保存它。 但这给了我下面给出的错误
array(3) {
[0]=>
array(1) {
["answer"]=>
string(218) "{"id":"19","question_id":"10","answer_text":"Please note that we also maintain you:",
"iscorrect":"1",
"created_at":"2014-06-07 07:52:12",
"updated_at":"2014-06-07 07:52:12"}"
}
[1]=>
array(1) {
["answer"]=>
string(218) "{"id":"20","question_id":"10","answer_text":"Please note that we also maintain the following pages and support forums to help you:",
"iscorrect":"1",
"created_at":"2014-06-07 07:52:13",
"updated_at":"2014-06-07 07:52:13"}"
}
[2]=>
array(1) {
["answer"]=>
string(218) "{"id":"21","question_id":"10",
"answer_text":"Please note that we also maintain the following pages and support forums to help you:","iscorrect":"0","created_at":"2014-06-07 07:52:13","updated_at":"2014-06-07 07:52:13"}"
}
}
{"error":{"type":"ErrorException","message":"Illegal string offset 'id'","file":"\/home\/learnomatics\/laravel\/mobillz_mlmalp\/app\/controllers\/QuizController.php","line":379}}
我正在尝试获得像
$answers=Input::get('answers');
var_dump($answers);
foreach ($answers as $answer) {
if(isset($answer['answer'])){
quiz_que_ans_id=$answer['answer']['id'];
}
}
$answer['answer']
变量是一个包含JSON编码数据的字符串; 要访问它,您需要先对其进行解码:
$data = json_decode($answer['answer'], true);
$quiz_queue_ans_id = $data['id']; // work with decoded data
在这里,您的答案包含一个json字符串。 在获取任何密钥之前对其进行解码。 尝试这个 :
foreach ($answers as $answer) {
if(isset($answer['answer'])){
$ans = json_decode($answer['answer'],true);
if(is_array($ans)){
quiz_que_ans_id=$ans['id'];
}
}
}
尝试以下操作,将照片传递到Form::file
门面。
{!! Form::file('photo', $user_master->photo, ['class' => 'control-label input-sm', 'type'=>'file', 'accept'=>'image/*']) !!}
代替
{!! Form::file('photo', null, ['class' => 'control-label input-sm', 'type'=>'file', 'accept'=>'image/*']) !!}`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.