Php JSON Array conversion error-php Tutorial

Source: Internet
Author: User
Tags parse error php json
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] =>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.