i have an json array and i want to parse it in java-script but my jquery gives me following error:
JSON.parse: unexpected character
The code in jquery is,on which the error comes:
// Attempt to parse using the native JSON parser first
if ( window.JSON && window.JSON.parse ) {//error comes on this line.
return window.JSON.parse( data );
}
My code is:
success: function(msg){
var test= JSON.parse(msg);
var question=test.question;
document.getElementById('question').value=question;
I am using the latest version of jquery
<script src="http://code.jquery.com/jquery-latest.js"></script>
I am getting this in function(msg):
[Object { question=
"What is your religious affiliation?"
, userQuestionCategoryId=
"1"
}]
Here is my Php code:
function getquest()
{
$id=$this->input->post('qid');
$data=$this->adminsetting->getquestion($id);
if(count($data)>0)
//echo $data[0]->question;
echo json_encode($data);
else
echo "No Question In database";
}
Thanks in advance.