简体   繁体   中英

How to encode json in php like this

{
  "status": "1",
  "error": "",
  "result": {
    "payment": {
      "issue_date": "2017-01-18",
      "payment_status": "Not Paid",
      "name": "GYM Master - GYM Management System",
      "address": "address",

    },
    "receiver": {
      "first_name": "Gauang",
      "last_name": "vyas",
      "address": "ldrp",
    }
  }
}

PHP has native function for encoding/decoding JSON

json_encode
json_decode

It accepts arrays and objects for your convienence.

Example:

$data = array(
   'status' => 1,
   'result' => array(
      'example' => 'example...'
   )
)

json_encode($data)

That will result in:

{
   "status":1,
   "result":{
      "example":"example..."
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM