如何仅从文本文件中的对象数组中获取特定字段

How to get only a Particular field from an object array in a text file

我正在尝试使用 file_get _contents 从文本文件中仅获取 you are doing that too much. try again in 1 minute 字段。请任何人解决这个问题。

{
    "jquery": [
        [
            0,
            1,
            "call",
            [
                "body"
            ]
        ],
        [
            1,
            2,
            "attr",
            "find"
        ],
        [
            2,
            3,
            "call",
            [
                ".status"
            ]
        ],
        [
            3,
            4,
            "attr",
            "hide"
        ],
        [
            4,
            5,
            "call",
            []
        ],
        [
            5,
            6,
            "attr",
            "html"
        ],
        [
            6,
            7,
            "call",
            [
                ""
            ]
        ],
        [
            7,
            8,
            "attr",
            "end"
        ],
        [
            8,
            9,
            "call",
            []
        ],
        [
            1,
            10,
            "attr",
            "find"
        ],
        [
            10,
            11,
            "call",
            [
                ".error.RATELIMIT.field-ratelimit"
            ]
        ],
        [
            11,
            12,
            "attr",
            "show"
        ],
        [
            12,
            13,
            "call",
            []
        ],
        [
            13,
            14,
            "attr",
            "text"
        ],
        [
            14,
            15,
            "call",
            [
                "you are doing that too much. try again in 1 minute."
            ]
        ],
        [
            15,
            16,
            "attr",
            "end"
        ],
        [
            16,
            17,
            "call",
            []
        ]
    ]
}

您可以直接使用评论中建议的 json_decode()ass。

如果转换成关联数组。 php.net

<?php

//input your json here
$json = '*** Your json ***'; 

//Decodes a JSON string, When TRUE, it will be converted into associative arrays. 
$array = json_decode($json, true);

//uncomment the next to line sif you want to echo the array
//echo "<pre>";
//print_r($array);

$text = $array['jquery'][14][3][0];
echo $text;

?>

或者如果不转换成关联数组

<?php

//input your json here
$json = '*** Your json ***'; 

//Decodes a JSON string. 
$array = json_decode($json);

//uncomment the next to line sif you want to echo the array
//echo "<pre>";
//print_r($array);

$text = $array->jquery[14][3][0];
echo $text;
?>

你差一点就成功了。访问数组时使用方括号。所以代替:

$arr->jquery->{'14'}->{'3'}->{'0'};

...使用...

$arr->jquery[14][3][0];