PHP json to array error help 1: output JSON combination of doctor information json $ jsonDoctorInfo & nbsp; {mecdoctor: [; $ jsonDoctorInfo & nbsp ;. & nbsp; {doctorId :. $ doctorId ., doctorName :. $ str php json Array conversion error for help
1: output json first
// Combine the doctor information JSON
$ JsonDoctorInfo = "{\" mecdoctor \":[";
$ JsonDoctorInfo. = "{\" doctorId \":\"". $ doctorId. "\", \ "doctorName \":\"". $ strDoctorName. "\", \ "doctorprice \":\"". $ strPrice. "\", \ "expertise \":\"". $ strExpertise. "\", \ "orders \":\"". $ strdepartments. "\", \ "doctorTitle \":\"". $ strTitle. "\", \ "doctorPhoto \":\"". $ strDoctorPhoto. "\"}";
$ JsonDoctorInfo. = "]}";
2: Get and decode
$ JsonGetDoctorInfoData = json_encode ($ jsonGetDoctorInfoData );
$ ObjGetDoctorInfoData = json_decode ($ jsonGetDoctorInfoData );
Output:
{"Mecdoctor": [{"doctorId": "", "doctorName": "XXXX", "doctorprice": "122", "expertise": "XXXXX ", "ments": "physician", "doctorTitle": "Chief physician", "doctorPhoto": "hmh"}]}
3: convert json into an array
// Parse JSON data
Function _ json_decode ($ json ){
$ Comment = false;
$ Out = '$ x = ';
For ($ I = 0; $ I
If (! $ Comment ){
If ($ json [$ I] = '{') | ($ json [$ I] = '['))
$ Out. = 'Array (';
Else if ($ json [$ I] = '}') | ($ json [$ I] = ']')
$ Out. = ')';
Else if ($ json [$ I] = ':')
$ Out. = '=> ';
Else
$ Out. = $ json [$ I];
} Else
$ Out. = $ json [$ I];
If ($ json [$ I] = '"' & $ json [($ i-1)]! = "\\")
$ Comment =! $ Comment;
}
Eval ($ out .";");
Return $ x;
}
4: Problems
Parse error: syntax error, unexpected T_DOUBLE_ARROW in/home/u945504094/public_html/config. inc. php (876): eval () 'd code on line 1
Share:
------ Solution --------------------
No problem
$ S = '{"mecdoctor": [{"doctorId": "", "doctorName": "XXXX", "doctorprice": "122", "expertise ": "XXXXX", "ments": "physician", "doctorTitle": "Chief physician", "doctorPhoto": "hmh"}]} ';
Print_r (_ json_decode ($ s ));
Function _ json_decode ($ json ){
$ Comment = false;
$ Out = '$ x = ';
For ($ I = 0; $ I
If (! $ Comment ){
If ($ json [$ I] = '{')
------ Solution --------------------
($ Json [$ I] = '['))
$ Out. = 'Array (';
Else if ($ json [$ I] = '}')
------ Solution --------------------
($ Json [$ I] = ']')
$ Out. = ')';
Else if ($ json [$ I] = ':')
$ Out. = '=> ';
Else
$ Out. = $ json [$ I];
} Else
$ Out. = $ json [$ I];
If ($ json [$ I] = '"' & $ json [($ i-1)]! = "\\")
$ Comment =! $ Comment;
}
Eval ($ out .";");
Return $ x;
}
Array
(
[mecdoctor] => Array
(
[0] => Array
(
[doctorId] =>