我试图使用PHP解析JSON文件.但我现在被困住了.
这是我的JSON文件的内容:
{
"John": {
"status":"Wait"
},
"Jennifer": {
"status":"Active"
},
"James": {
"status":"Active",
"age":56,
"count":10,
"progress":0.0029857,
"bad":0
}
}
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止所尝试的:
<?php
$string = file_get_contents("/home/michael/test.json");
$json_a = json_decode($string, true);
echo $json_a['John'][status];
echo $json_a['Jennifer'][status];
Run Code Online (Sandbox Code Playgroud)
但是,因为我不知道的名字(例如'John','Jennifer')和所有可用键和值(如'age','count')事前,我想我需要创建一些foreach循环.
我会很感激这样的例子.
我在Windows 7上运行PHP版本5.6.3作为XAMPP的一部分.
当我尝试使用Mandrill API时,我收到以下错误:
未捕获的异常'Mandrill_HttpError',消息'API调用消息/发送模板失败:SSL证书问题:无法获取本地颁发者证书'
我已经尝试过在StackOverflow上阅读的所有内容,包括将以下内容添加到php.ini文件中:
curl.cainfo = "C:\xampp\php\cacert.pem"
Run Code Online (Sandbox Code Playgroud)
并且当然从http://curl.haxx.se/docs/caextract.html下载到该位置的cacert.pem文件
但毕竟,重新启动XAMPP和Apache服务器但仍然得到相同的错误.
我真的不知道还有什么可以尝试的.
任何人都可以建议我还能尝试什么?
所以我有一个返回jSON对象的链接,我需要将它解码并放入PHP中的变量中.
网址
api.php?action=getThreads&hash=123fajwersa&node_id=4&order_by=post_date&order=desc&limit=1&grab_content&content_limit=1
Run Code Online (Sandbox Code Playgroud)
这是它返回的对象
{
"count": 1,
"threads": {
"38752": {
"thread_id": 38752,
"node_id": 4,
"title": "The ShadyCraft Beta Launch!",
"reply_count": 45,
"view_count": 946,
"user_id": 2,
"username": "Shady",
"post_date": 1366956695,
"sticky": 0,
"discussion_state": "visible",
"discussion_open": 1,
"discussion_type": "",
"first_post_id": 226167,
"first_post_likes": 7,
"last_post_date": 1369094302,
"last_post_id": 228226,
"last_post_user_id": 2,
"last_post_username": "Shady",
"prefix_id": 19,
"tinhte_xentag_tags": "a:4:{i:0;s:9:\"minecraft\";i:2;s:4:\"news\";i:3;s:14:\"private server\";i:1;s:10:\"shadycraft\";}",
"content": {
"count": 1,
"content": {
"226167": {
"post_id": 226167,
"thread_id": 38752,
"user_id": 2,
"username": "Shady",
"post_date": 1366956695,
"message": "[ATTACH=full]4143[\/ATTACH]\n \nWe've completely restructured ShadyCraft, and …Run Code Online (Sandbox Code Playgroud) 嗨,我对PHP和Messenger Bots编码很新.
我想知道如何访问我的聊天机器人的名字.