Sign in to follow this  
Followers 0
𝙡𝙖𝙨𝙩 𝙚𝙢𝙥𝙚𝙧𝙤𝙧.

Работа с JSON файлом.

4 posts in this topic

Всех приветствую.

Возник небольшой вопрос.
Есть .json файл с такой структурой:

Спойлер

{
    "query": [
        {
            "number": 1,
            "name": "arz",
            "ip": "127.0.0.1",
            "port": 7777,
            "online": 0,
            "maxplayers": 100,
            "password": false,
            "plotPoints": [
                {
                    "online": 0,
                    "time": 1624076223
                },
                {
                    "online": 15,
                    "time": 1624079883
                },
                {
                    "online": 14,
                    "time": 1624083542
                },
                {
                    "online": 18,
                    "time": 1624087143
                },
                {
                    "online": 22,
                    "time": 1624090802
                },
                {
                    "online": 19,
                    "time": 1624094463
                }
            ]
        }
    ]
}

 


Вопрос такой: как через PHP менять значение online по К/Д (допустим, раз в минуту)?
Заранее, спасибо.

Share this post


Link to post
Share on other sites

Используете функцию https://www.php.net/manual/ru/function.json-decode.php, после чего в массиве, который получился после декодирования меняете online и заново кодируете в JSON через json_encode

Share this post


Link to post
Share on other sites

@DEST, но кодирует ли он правильно обратно? В файле семь значений "online".

Share this post


Link to post
Share on other sites

@glvde. значит их изменять нужно в цикле. А для json_encode неважно сколько у вас значений и насколько сложная структура вложенности, он любую закодирует в JSON. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.