将JSON导入CodeIgni

2024-04-23 08:02:27 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在CodeIgniter中导入和使用JSON?例如,下面的代码片段是用Python编写的,它将Reddit's front page转换为JSON并打印密钥:

reddit_front = r"""{"kind": "Listing", "data": {"modhash": "", "children": ...  """

import json
j = json.loads(reddit_front)
print j.keys()

Tags: 代码importjsondatapage密钥listingfront
1条回答
网友
1楼 · 发布于 2024-04-23 08:02:27

如果您有一个json字符串,您可以在php中使用下面的函数来读取json字符串。在

$result is the json string for example

$res = json_decode($result,true);

现在使用foreach遍历$res以打印值

相关问题 更多 >