javascript-php reading a JSON file and finding its contents

Source: Internet
Author: User
Keywords Php javascript


Do you have this? A JSON format file X.json

Now PHP wants to read the contents of the JSON file and find the item in the bundle as required
Example: Output Dkey value via A03
How do I find the corresponding output? For advice

Error

Reply content:


Do you have this? A JSON format file X.json

Now PHP wants to read the contents of the JSON file and find the item in the bundle as required
Example: Output Dkey value via A03
How do I find the corresponding output? For advice

Error

Your JSON file has a BOM header,

$json = file_get_contents (' Qcode.json '); $arr = Json_decode (Trim ($json, Chr (239). chr (187). Chr (191)), true); $temp = Arra Y_column ($arr, ' Dkey ', ' dvalue '); Echo $temp [' A05 '];if (! function_exists (' Array_column ')) {function Array_column (ARRA        Y $input, $columnKey, $indexKey = null) {$array = array (); foreach ($input as $value) {if (! isset ($value [$columnKey])) {trigger_error ("Key \" $columnKey \                "does not exist in array");            return false;            } if (Is_null ($indexKey)) {$array [] = $value [$columnKey]; } else {if (! isset ($value [$indexKey])) {trigger_error ("Key \" $indexKey \ "does not exi                    St in Array ");                return false; } if (! is_scalar ($value [$indexKey])) {trigger_error ("Key \" $indexKey \ "does not contai                    N scalar value ");                return false; } $array[$value [$indexKey]] = $value [$columnKey];    }} return $array; }}

Var_dump (Json_decode ($json));

Print out all the values first, and you'll know how to call them.

  • Related Article

    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.