$json = file_get_contents('file.json');
$json_read = json_decode($json, true);
unset($json_read['posts'][2]);
$json_read_posts = array_values($json_read['posts']);
$json_edit_ = json_encode($json_read_posts, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
$array = json_decode('{"posts": []}', true);
$array = array("posts" => ( json_decode($json_edit_) ));
$json_edit = json_encode($array, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
echo($json_edit);
$json = file_get_contents('file.json');
$json_read = json_decode($json, true);
unset($json_read['posts'][1]);
$json_read_posts = array_values($json_read['posts']);
$json_edit = json_encode($json_read_posts, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
echo ($json_edit);
[
{
"id": 0,
"title": "Авто - 1",
"description": "Описание",
"active": true
},
{
"id": 2,
"title": "Авто 3",
"description": "Описание - 1",
"active": true
}
]
Но пропало "posts", как сделать что-бы оно вернулось и было вот так:{
"posts": [
{
"id": 0,
"title": "Авто 1",
"description": "Описание",
"active": true
},
{
"id": 2,
"title": "Авто 3",
"description": "Описание - 1",
"active": true
}
]
}
$json = file_get_contents('file.json');
$json_read = json_decode($json, true);
unset($json_read['posts'][1]);
$json_read_posts = array_values($json_read['posts']);
$json_reads = json_encode($json_read_posts, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
echo ($json_reads);
<?php
$jsondata = file_get_contents('file.json');
$data = json_decode($jsondata);
$data->posts = (array)$data->posts;
var_dump ($data);
unset($data['posts'][1]);
?>
Fatal error: Uncaught Error: Cannot use object of type stdClass as array in D:\OpenServer\domains\site.com\file.php:7 Stack trace: #0 {main} thrown in D:\OpenServer\domains\site.com\file.php on line 7
# -*- coding: utf-8 -*-
import sys
from PySide2 import QtCore, QtGui, QtWidgets
from PySide2.QtWidgets import QApplication
from PySide2.QtWebEngineWidgets import *
from PySide2.QtCore import QUrl
import PySide2.QtWidgets
from PySide2.QtWebEngineWidgets import QWebEngineSettings, QWebEngineView, QWebEnginePage
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(718, 476)
self.verticalLayoutWidget = QtWidgets.QWidget(Form)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(100, 10, 601, 461))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(10, 10, 75, 461))
self.pushButton.setObjectName("pushButton")
self.web = QWebEngineView()
self.web.load(QUrl("https://docs.google.com/spreadsheets/d/e/2PACX-1vQPUnoHt_9snIRe8OCM5FS85k1auXH7-tBCQ7m5IM8OKNuQIst6eVoDBL8Uvwvk7tgzwYX2MgxojaNq/pubhtml?widget=true"))
self.html = self.web.page().toHtml(self.web)
self.verticalLayout.addWidget(self.web)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton.setText(_translate("Form", "L\n"
"O\n"
"A\n"
"D"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
import sys
from PySide2 import QtCore, QtGui, QtWidgets
from PySide2.QtWidgets import QApplication
from PySide2.QtWebEngineWidgets import *
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(781, 423)
self.textBrowser = QtWidgets.QTextBrowser(Form)
self.textBrowser.setGeometry(QtCore.QRect(440, 20, 342, 404))
self.textBrowser.setObjectName("textBrowser")
self.retranslateUi(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
TypeError: can only concatenate str (not "int") to str