将新数据添加到PHP JSON字符串 [英] Add new data into PHP JSON string

查看:123
本文介绍了将新数据添加到PHP JSON字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有$ data作为JSON编码的数据,并且我有这个字符串:

I have $data as JSON encoded data and I have this string:

$new_data = "color:'red'";

需要添加到$ data中,以便我可以将其作为json字符串从中读取.

that needs to be added to $data so that I can read it from it as a json string.

我该如何实现?

推荐答案

您需要先json_decode($data),然后添加新的键/值,然后json_encode().

you need to json_decode($data) first, then add the new key/value, and json_encode() it.

这篇关于将新数据添加到PHP JSON字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆