【问题标题】:how to read json data in php codeigniter如何在 php codeigniter 中读取 json 数据
【发布时间】:2017-02-09 21:11:11
【问题描述】:

以下是我使用 ajax 发送到 php 控制器的 json 数据

[  
   {  
      "First":"A,b"
   },
   {  
      "Second":""
   },
   {  
      "Third":""
   },
   {  
      "Fourth":""
   },
   {  
      "Fifth":""
   },
   {  
      "Sixth":""
   },
   {  
      "Seventh":""
   },
   {  
      "Eight":""
   },
   {  
      "Ninth":""
   },
   {  
      "Tenth":""
   }
]

如何读取值并将其存储在 php 变量中或使用上述 json 字符串的循环

【问题讨论】:

标签: php json ajax codeigniter


【解决方案1】:

您需要使用json_decode() 解码您的json 字符串,而不是使用foreach() 循环。

print_r(json_decode($jsonString,TRUE)); // will return response in an array

print_r(json_decode($jsonString)); // will return response in an object

您可以将数据读取为:

$decoded = json_decode($jsonString,TRUE);

foreach( $decoded as $key => $value ){
    // print values
    // print key
}

【讨论】:

  • 是的,我已经解码了,但我不知道如何在解码后从中读取或提取数据
【解决方案2】:

尝试使用PHP内置函数json_decode

http://www.php.net/manual/en/function.json-decode.php

然后像数组一样访问它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    • 2013-04-16
    • 1970-01-01
    • 2016-04-01
    • 1970-01-01
    相关资源
    最近更新 更多