dounabi6295 2014-05-15 06:36
浏览 29
已采纳

如何从PHP读取JSON结果

How to access element of below json output using php ..

{
    "ISBN:9781430215752": {
        "bib_key": "ISBN:9781430215752",
        "preview":
                "restricted",
        "preview_url":
                "https://archive.org/details/linuxrecipesforo00kuhn",
        "info_url": "https://openlibrary.org/books/OL23936576M/Linux_recipes_for_Oracle_DBAs",
        "details": {
            "lc_classifications": ["QA76.9.D3 K84 2009"],
            "latest_revision": 2,
            "ocaid": "linuxrecipesforo00kuhn",
            "contributions": ["Kim, Charles.", "Lopuz, Bernard."],
            "source_records": ["marc:marc_loc_updates/v37.i44.records.utf8:10470755:1047"],
            "title":
                    "Linux recipes for Oracle DBAs",
            "languages": [{
                    "key": "/languages/eng"
                }],
            "subjects": ["Linux", "Oracle (Computer file)", "Relational databases", "Database management"],
            "publish_country": "cau",
            "by_statement": "Darl Kuhn, Charles Kim, Bernard Lopuz.",
            "type": {
                "key": "/type/edition"
            },
            "revision": 2,
            "other_titles": ["Linux recipes for Oracle DataBase Administrators"],
            "publishers": ["Apress", "Distributed to the book trade by Springer-Verlag"],
            "last_modified": {
                "type": "/type/datetime",
                "value": "2014-04-06T06:55:36.956977"
            },
            "key": "/books/OL23936576M",
            "authors": [{
                    "name": "Darl Kuhn",
                    "key": "/authors/OL1484587A"
                }],
            "publish_places": ["Berkeley, CA", "New York"],
            "oclc_number": ["243543902"],
            "pagination": "xxv, 501 p. :",
            "created": {
                "type": "/type/datetime",
                "value": "2009-11-24T23:42:39.524606"
            },
            "dewey_decimal_class": ["005.75/65 22", "005.26/8"],
            "notes": {
                "type": "/type/text",
                "value": "Includes index."
            },
            "number_of_pages": 501,
            "isbn_13": ["9781430215752"],
            "lccn": ["2009277832"],
            "isbn_10": ["1430215755"],
            "publish_date": "2008"
        }
    }
}

I tried using below code,
it doesn't work.

$json = json_decode($body);

echo $json->ISBN:9780980200447->info_url;

It's giving an error..

Is there any other easy way to read all elements?

  • 写回答

4条回答 默认 最新

  • dtk31564 2014-05-15 06:43
    关注

    You are on the right track. : is just an invalid character for a property and must be handled special.

    echo $json->{'ISBN:9781430215752'}->info_url;
    

    will get you the expected result.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗