PHP中的非法字符串偏移错误

Saj*_*mad 1 php laravel laravel-4

我将这些对象发送到服务器以获取记录并保存.但它给了我下面给出的错误

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}}
Run Code Online (Sandbox Code Playgroud)

我试图得到像这样的价值观

$answers=Input::get('answers');
var_dump($answers);
foreach ($answers as $answer) {
    if(isset($answer['answer'])){
        quiz_que_ans_id=$answer['answer']['id'];
}
}
Run Code Online (Sandbox Code Playgroud)

Ja͢*_*͢ck 6

$answer['answer']变量是包含JSON编码数据的字符串; 要访问它,您需要先解码它:

$data = json_decode($answer['answer'], true);
$quiz_queue_ans_id = $data['id']; // work with decoded data
Run Code Online (Sandbox Code Playgroud)