如何在PHP中轻松访问JSON(比如具有多个字段的JSON记录集)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在PHP中轻松访问JSON(比如具有多个字段的JSON记录集)相关的知识,希望对你有一定的参考价值。
<?php // json is here a field, but can be your input too. This is for educational purposes // this sample is the output from an Extjs Ajax call, submitting a complete grid back // to the server $json = '{ "success" : "true", "message" : "OK", "total" : "3", "records" : [ { "se_pkey": "DE", "se_langvalue": "Deutsch", "se_picon": "de", "se_pvalue": "Lehrinstitut", "se_pshow": "1", "se_id": "216" }, { "se_pkey": "EN", "se_langvalue": "Englisch", "se_picon": "en", "se_pvalue": "Institute", "se_pshow": "1", "se_id": "227" }, { "se_pkey": "NL", "se_langvalue": "Niederl\u00e4ndisch", "se_picon": "nl", "se_pvalue": null, "se_pshow": null, "se_id": null } ] }'; foreach ( $exjson['records'] as $row ) { // loop the records echo 'To access fields, this works too: '. $row['se_id']. '<br/>'; foreach ( $row as $field => $value ) { // loop the fields // $field = field name // $row = record // $value = field value echo $field . ': '. $value . '<br>'; } echo '<br/>'; } ?>
以上是关于如何在PHP中轻松访问JSON(比如具有多个字段的JSON记录集)的主要内容,如果未能解决你的问题,请参考以下文章
将具有多个字段的表单数据转换为 JSON Jquery Javascript