duanhuilao0787 2018-08-08 03:52 采纳率: 100%
浏览 93

JSON PHP服务器已修改

The following is my JSON data.

[
  {
    "id": 1,
    "Name": {
      "FirstName": "Wilmer",
      "LastName": "Crona",
      "FullName": "Mr. Cameron Prosacco"
    },
    "Address": {
      "Address1": "84154 Vickie Burg Apt. 994",
      "Address2": "Suite 339",
      "ZipCode": "89080-0376"
    },
    "Phone": "316-269-7694 x1364"
  },
  {
    "id": 2,
    "Name": {
      "FirstName": "Mercedes",
      "LastName": "Kshlerin",
      "FullName": "Dr. Kellie Bashirian"
    },
    "Address": {
      "Address1": "12638 Cali Spurs",
      "Address2": "Suite 353",
      "ZipCode": "76622"
    },
    "Phone": "319-329-3169 x8848"
  }
]

Here is where I want my JSON like this: https://github.com/Zlob/php-json-server but in the method. The JSON file must one file and process only one JSON (db.json).

If my JSON file json1.json , json2.json, etc. How should I do?

  • 写回答

2条回答 默认 最新

  • dsf6565 2018-08-08 04:16
    关注

    You can't decode only first element, you can decode all and get first element only, here is online compiler

    <?php
    
    $json = '[
    {
        "id": 1,
         "Name": {
         "FirstName": "Wilmer",
         "LastName": "Crona",
         "FullName": "Mr. Cameron Prosacco"
       },
       "Address": {
         "Address1": "84154 Vickie Burg Apt. 994",
         "Address2": "Suite 339",
         "ZipCode": "89080-0376"
       },
       "Phone": "316-269-7694 x1364"
     },
     {
       "id": 2,
       "Name": {
         "FirstName": "Mercedes",
         "LastName": "Kshlerin",
         "FullName": "Dr. Kellie Bashirian"
       },
       "Address": {
         "Address1": "12638 Cali Spurs",
         "Address2": "Suite 353",
         "ZipCode": "76622"
       },
       "Phone": "319-329-3169 x8848"
     }
    ]';
    $data = json_decode($json);
    $firstObject = $data[0];
    var_dump($firstObject);
    
    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法