PHP json to array error help

Source: Internet
Author: User
Tags parse error php json
1: Output JSON first
Combination Doctor information Json$jsondoctorinfo  = "{\" mecdoctor\ ": ["; $jsonDoctorInfo. = "{\" doctorid\ ": \" ". $doctorId." \ ", \" doctorname\ ": \" ". $strDoctorName." \ ", \" doctorprice\ ": \" ". $strPrice." \ ", \" expertise\ ": \" ". $strExpertise." \ ", \" departments\ ": \" ". $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", "Departments": "Medical Internal Medicine", " Doctortitle ": Chief Physician", "Doctorphoto": "HMH"}]}

3: Convert JSON to an array
Parse JSON data function _json_decode ($json) {$comment = false; $out = ' $x = '; for ($i =0; $i
   
  
4: There is a problem
Parse error:syntax error, unexpected T_double_arrow in/home/u945504094/public_html/config/config.inc.php (876): eval ( ) ' d Code on line 1



Reply to discussion (solution)

Please help me to see where the hell is wrong.

$s = ' {"Mecdoctor": [{"Doctorid": "", "Doctorname": "XXXX", "Doctorprice": "122", "expertise": "XXXXX", "Departments": " Medical internal Medicine "," Doctortitle ":" Chief Physician "," Doctorphoto ":" HMH "}]} ';p Rint_r (Json_decode ($s, true));
Array ([    mecdoctor] = = Array (            [0] = = Array                (                    [Doctorid] =                     [Doctorname] = XXXX                    [Doctorprice] = 122                    [Expertise] = XXXXX                    [Departments] = Medical Department                    [Doctortitle] = chief physician                    [Doctorphoto] = HMH                ) c12/>))
You didn't give the code near the wrong line, and naturally you don't know what's wrong with you.

Thank you Moderator,
After I get the JSON in the second step, I bring $s into function _json_decode ($json) {error occurred in
4: There is a problem
Parse error:syntax error, unexpected T_double_arrow in/home/u945504094/public_html/config/config.inc.php (876): eval ( ) ' d Code on line 1



$s = ' {"Mecdoctor": [{"Doctorid": "", "Doctorname": "XXXX", "Doctorprice": "122", "expertise": "XXXXX", "Departments": " Medical internal Medicine "," Doctortitle ":" Chief Physician "," Doctorphoto ":" HMH "}]} ';p Rint_r (Json_decode ($s, true));
Array ([    mecdoctor] = = Array (            [0] = = Array                (                    [Doctorid] =                     [Doctorname] = XXXX                    [Doctorprice] = 122                    [Expertise] = XXXXX                    [Departments] = Medical Department                    [Doctortitle] = chief physician                    [Doctorphoto] = HMH                ) c12/>))
You didn't give the code near the wrong line, and naturally you don't know what's wrong with you.

Also ask, why I get the JSON string through File_get_content, decode when the true parameter can not parse the array, but directly to the obtained JSON to a variable after the test can be transferred to the group?

$urlGetDoctorInfo = "http://127.0.0.1:8080/mobileInterface/mobileDataInterface.php?" Action=showdoctorinfo&doctorid= ". $_request[' Doctorid '); $jsonGetDoctorInfoData =  file_get_contents ($ Urlgetdoctorinfo);p Rint_r (Json_decode ($jsonGetDoctorInfoData, True));//data is empty//the string is worn to the variable $s= ' {' mecdoctor ': [{' Doctorid ":" "," Doctorname ":" xxx "," Doctorprice ":" 122 "," expertise ":" XXX "," Departments ":" Internal Medicine "," Doctortitle ":" Chief Physician ", "Doctorphoto": "HMH"}]} ';p Rint_r (Json_decode ($s, true));//Normal output

May I ask why this is?

No problem.

$s = ' {"Mecdoctor": [{"Doctorid": "", "Doctorname": "XXXX", "Doctorprice": "122", "expertise": "XXXXX", "Departments": "    Medical internal Medicine "," Doctortitle ":" Chief Physician "," Doctorphoto ":" HMH "}]} ';p Rint_r (_json_decode ($s));        function _json_decode ($json) {$comment = false;        $out = ' $x = '; for ($i =0; $i
     
    
Array ([    mecdoctor] = = Array (            [0] = = Array                (                    [Doctorid] =                     [Doctorname] = XXXX                    [Doctorprice] = 122                    [Expertise] = XXXXX                    [Departments] = Medical Department                    [Doctortitle] = chief physician                    [Doctorphoto] = HMH                ) c12/>))

Yes, the moderator, but the file is not available.
Also ask, why I get the JSON string through File_get_content, decode when the true parameter can not parse the array, but directly to the obtained JSON to a variable after the test can be transferred to the group?

$urlGetDoctorInfo = "http://127.0.0.1:8080/mobileInterface/mobileDataInterface.php?" Action=showdoctorinfo&doctorid= ". $_request[' Doctorid '); $jsonGetDoctorInfoData =  file_get_contents ($ Urlgetdoctorinfo);p Rint_r (Json_decode ($jsonGetDoctorInfoData, True));//data is empty//the string is worn to the variable $s= ' {' mecdoctor ': [{' Doctorid ":" "," Doctorname ":" xxx "," Doctorprice ":" 122 "," expertise ":" XXX "," Departments ":" Internal Medicine "," Doctortitle ":" Chief Physician ", "Doctorphoto": "HMH"}]} ';p Rint_r (Json_decode ($s, true));//Normal output

May I ask why this is?

$urlGetDoctorInfo = "http://127.0.0.1:8080/mobileInterface/mobileDataInterface.php?" Action=showdoctorinfo&doctorid= ". $_request[' Doctorid '); $jsonGetDoctorInfoData =  file_get_contents ($ Urlgetdoctorinfo);p Rint_r (Json_decode ($jsonGetDoctorInfoData, True));//data is empty//the string is worn to the variable $s= ' {' mecdoctor ': [{' Doctorid ":" "," Doctorname ":" xxx "," Doctorprice ":" 122 "," expertise ":" XXX "," Departments ":" Internal Medicine "," Doctortitle ":" Chief Physician ", "Doctorphoto": "HMH"}]} ';p Rint_r (Json_decode ($s, true));//Normal output publishers, please see what the problem is, just the problem.

No problem.
$s = ' {"Mecdoctor": [{"Doctorid": "", "Doctorname": "XXXX", "Doctorprice": "122", "expertise": "XXXXX", "Departments": "    Medical internal Medicine "," Doctortitle ":" Chief Physician "," Doctorphoto ":" HMH "}]} ';p Rint_r (_json_decode ($s));        function _json_decode ($json) {$comment = false;        $out = ' $x = '; for ($i =0; $i
     
       
       
array ([mecdoctor] = = Array ([0] = = Array ([Doctorid] = [Doctorname] = XXXX [Doctorprice] = > 122 [Expertise] = XXXXX [Departments] = Medical Internal Medicine [Doctort Itle] = chief Physician [Doctorphoto] = HMH)) 

That's the coding problem!
Json_decode can only recognize UTF-8 encoded data

  • 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.