PHP takes out JSON returns null

Source: Internet
Author: User
The code is as follows:


  
    $obj->songs[0]->bMusic->name,    "artist" => $obj->songs[0]->artists[0]->name,    "url" => $obj->songs[0]->mp3Url);echo json_encode($array);?>

The JSON file is roughly like this:

{"Songs": [{"Starred": false, "popularity": Up, "Starrednum": 0, "Playednum": 0, "Dayplays": 0, "Heartime": 0, "Mp3url": "Http://m2.music.126.net/2b980AHt            Vx18bj_z9mhkxa==/2830142929914115.mp3 "," Rturls ": []," status ": 1," CRBT ": null,                 "Bmusic": {"Volumedelta": 0.095421, "playTime": 200000, "bitrate": 96000,                "Dfsid": 2830142929914115, "sr": 44100, "name": "Set Fire to the Rain", "id": 24667967, "size": 2436177, "extension": "MP3"}, "RtU                RL ": null," position ": 2," duration ": 200000," Alias ": []," Hmusic ": {  "Volumedelta": -0.05, "playTime": 200000, "bitrate": 320000, "Dfsid":      2830142929914113,          "SR": 44100, "name": "Set Fire to the Rain", "id": 24667965, "size"                : 8056892, "extension": "MP3"}, "Mmusic": {"Volumedelta": 0.41,                "PlayTime": 200000, "bitrate": 160000, "Dfsid": 2830142929914114,                 "SR": 44100, "name": "Set Fire to the Rain", "id": 24667966, "size": 4042394,                "Extension": "MP3"}, "Lmusic": {"Volumedelta": 0.095421, "PlayTime": 200000, "bitrate": 96000, "Dfsid": 2830142929914115, "SR": 4                4100, "name": "Set Fire to the Rain", "id": 24667967, "size": 2436177,                "Extension": "MP3"}, "album": {"songs": [], "paid": false, "OnSale": False, "status": 1, "tags": "", "Blurpicurl": "HTTP://P4.MUSIC.126.NET/J32CG                J_dq-4wpfs4u9sjwa==/2539871860943087.jpg "," CompanyID ": 0," pic ": 2539871860943087, "description": "", "subtype": null, "Alias": [], "picid": 253987186094 3087, "Briefdesc": "", "Artist": {"Img1v1id": 0, "Ali As ": []," Picid ": 0," Briefdesc ":" "," Picurl ":" Http://p4.music.  126.net/6y-uleoritedbvrolv0q8a==/5639395138885805.jpg "," Albumsize ": 0," Img1v1url ":                    "Http://p3.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg", "Trans": "", "Musicsize": 0, "name": "", "id": 0}, "Picurl": "H Ttp://p4.music.126.net/j32cgj_dq-4wpfs4u9sjwa==/2539871860943087.jpg "," Commentthreadid ":" r_al_3_1983765 "," artists                        ": [{" Img1v1id ": 0," Alias ": [], "Picid": 0, "Briefdesc": "", "Picurl": "Http://p4.music.126.net/6y-UleORITE Dbvrolv0q8a==/5639395138885805.jpg "," Albumsize ": 0," Img1v1url ":" Http://p3                        . Music.126.net/6y-uleoritedbvrolv0q8a==/5639395138885805.jpg "," Trans ":" ",                    "Musicsize": 0, "name": "Piano Tribute Players", "id": 99094 }], "Copyrightid": 0, "publishtime": 1321804800000, "comp Any ': ' CC entertainment ', ' name ': ' Piano tribute to Adele ', ' id ': 1983765, ' t             Ype ":" album ",   "Size": "Commentthreadid": "r_so_4_21515271", "artists": [{ "Img1v1id": 0, "Alias": [], "Picid": 0, "Briefdesc                    ":" "," Picurl ":" Http://p3.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg ", "Albumsize": 0, "Img1v1url": "HTTP://P4.MUSIC.126.NET/6Y-ULEORITEDBVROLV0Q8A==/5639395138885805.J PG "," Trans ":" "," Musicsize ": 0," name ":" Piano Tribute Players "            , "id": 99094}], "Copyrightid": 0, "score": 95, "Fee": 0, "Mvid": 0, "ftype": 0, "Rtype": 0, "Rurl": null, "C            Opyfrom ":", "audition": null, "Ringtone": "", "Disc": "", "No": 2, "Name": "Set fire to THe Rain "," id ": 21515271}]," Equalizers ": {}," code ": 200} 

Upload to host page output result:

Notice:trying to get property of Non-object in on line 6 {"name": null, "Artist": "Piano Tribute Players", "url": null}

Reply content:

The code is as follows:


  
    $obj->songs[0]->bMusic->name,    "artist" => $obj->songs[0]->artists[0]->name,    "url" => $obj->songs[0]->mp3Url);echo json_encode($array);?>

The JSON file is roughly like this:

{"Songs": [{"Starred": false, "popularity": Up, "Starrednum": 0, "Playednum": 0, "Dayplays": 0, "Heartime": 0, "Mp3url": "Http://m2.music.126.net/2b980AHt            Vx18bj_z9mhkxa==/2830142929914115.mp3 "," Rturls ": []," status ": 1," CRBT ": null,                 "Bmusic": {"Volumedelta": 0.095421, "playTime": 200000, "bitrate": 96000,                "Dfsid": 2830142929914115, "sr": 44100, "name": "Set Fire to the Rain", "id": 24667967, "size": 2436177, "extension": "MP3"}, "RtU                RL ": null," position ": 2," duration ": 200000," Alias ": []," Hmusic ": {  "Volumedelta": -0.05, "playTime": 200000, "bitrate": 320000, "Dfsid":      2830142929914113,          "SR": 44100, "name": "Set Fire to the Rain", "id": 24667965, "size"                : 8056892, "extension": "MP3"}, "Mmusic": {"Volumedelta": 0.41,                "PlayTime": 200000, "bitrate": 160000, "Dfsid": 2830142929914114,                 "SR": 44100, "name": "Set Fire to the Rain", "id": 24667966, "size": 4042394,                "Extension": "MP3"}, "Lmusic": {"Volumedelta": 0.095421, "PlayTime": 200000, "bitrate": 96000, "Dfsid": 2830142929914115, "SR": 4                4100, "name": "Set Fire to the Rain", "id": 24667967, "size": 2436177,                "Extension": "MP3"}, "album": {"songs": [], "paid": false, "OnSale": False, "status": 1, "tags": "", "Blurpicurl": "HTTP://P4.MUSIC.126.NET/J32CG                J_dq-4wpfs4u9sjwa==/2539871860943087.jpg "," CompanyID ": 0," pic ": 2539871860943087, "description": "", "subtype": null, "Alias": [], "picid": 253987186094 3087, "Briefdesc": "", "Artist": {"Img1v1id": 0, "Ali As ": []," Picid ": 0," Briefdesc ":" "," Picurl ":" Http://p4.music.  126.net/6y-uleoritedbvrolv0q8a==/5639395138885805.jpg "," Albumsize ": 0," Img1v1url ":                    "Http://p3.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg", "Trans": "", "Musicsize": 0, "name": "", "id": 0}, "Picurl": "H Ttp://p4.music.126.net/j32cgj_dq-4wpfs4u9sjwa==/2539871860943087.jpg "," Commentthreadid ":" r_al_3_1983765 "," artists                        ": [{" Img1v1id ": 0," Alias ": [], "Picid": 0, "Briefdesc": "", "Picurl": "Http://p4.music.126.net/6y-UleORITE Dbvrolv0q8a==/5639395138885805.jpg "," Albumsize ": 0," Img1v1url ":" Http://p3                        . Music.126.net/6y-uleoritedbvrolv0q8a==/5639395138885805.jpg "," Trans ":" ",                    "Musicsize": 0, "name": "Piano Tribute Players", "id": 99094 }], "Copyrightid": 0, "publishtime": 1321804800000, "comp Any ': ' CC entertainment ', ' name ': ' Piano tribute to Adele ', ' id ': 1983765, ' t             Ype ":" album ",   "Size": "Commentthreadid": "r_so_4_21515271", "artists": [{ "Img1v1id": 0, "Alias": [], "Picid": 0, "Briefdesc                    ":" "," Picurl ":" Http://p3.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg ", "Albumsize": 0, "Img1v1url": "HTTP://P4.MUSIC.126.NET/6Y-ULEORITEDBVROLV0Q8A==/5639395138885805.J PG "," Trans ":" "," Musicsize ": 0," name ":" Piano Tribute Players "            , "id": 99094}], "Copyrightid": 0, "score": 95, "Fee": 0, "Mvid": 0, "ftype": 0, "Rtype": 0, "Rurl": null, "C            Opyfrom ":", "audition": null, "Ringtone": "", "Disc": "", "No": 2, "Name": "Set fire to THe Rain "," id ": 21515271}]," Equalizers ": {}," code ": 200} 

Upload to host page output result:

Notice:trying to get property of Non-object in on line 6 {"name": null, "Artist": "Piano Tribute Players", "url": null}

JSON also has two commands:
Json_last_error_msg This is the error message that gets the JSON.
Json_last_error returns the last error that occurred
You can try these two commands to see what's wrong with Json_encode.

Remember to read the PHP manual on a similar wording:

$obj->{$music->name}

This kind of, do not know whether there is any relationship ...
(similar to the scene I used to use more than the array, I feel in PHP more useful than the object ...) Beginner to Forgive ~)

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