<?php
$json= '{
"fields" :
[
{
"name" : "news_title",
"type" : "text",
"value" : "old title"
},
{
"name" : "news_content",
"type" : "textarea",
"value" : "old content"
}
]
}';
echo $json;
$jsonInPHP = json_decode($json,true);
$results = count($jsonInPHP['fields']);
for ($r = 0; $r < $results; $r++){
// look for the entry we are trying to find
if ($jsonInPHP->fields[$r]['name'] == 'news_title'
&& $jsonInPHP->fields[$r]->value == 'old title'){
// remove the match
unset($jsonInPHP->fields[$r]);
if(empty($jsonInPHP->fields[$r]->value))
{
$jsonInPHP['fields'][$r]['name'] == 'news_title';
$jsonInPHP->fields[$r]->value=='no';
}
break;
}
}
function gog($status)
{
$results = count($status->fields);
for ($r = 0; $r < $results; $r++){
$status->fields[$r]->value == 'old rr';
}
}
$jsonInPHP->fields = array_values($jsonInPHP->fields);
echo json_encode($jsonInPHP);
?>
我想从
搜索后改变'{“fields”:[{“name”:“news_title”,“type”:“text”,“value”:“old title”},{“name”:“news_content”,“type”: “textarea”,“value”:“old content”}]}'
到
'{“fields”:[{“name”:“news_title”,“type”:“text”,“value”:“我的新标题”},{“name”:“news_content”,“type” :“textarea”,“value”:“我的新内容”}]}'
答案 0 :(得分:0)
检查json_decode的官方文档功能json_decode($json,true);
的第二个参数(在您的情况下为true
)确定结果是否将转换为关联数组。如果您想将结果用作对象,请将该值设置为false
或更好地省略该值。