我有一个如下所示的数组:
[
{"value": {
"api_rev":"1.0",
"type":"router",
"hostname":"Router Hasselt",
"lat":50.9307,
"lon":5.33248,
"elev":50,
"aliases":[
{
"type":"wired",
"alias":"11.96.253.9"
}],
"community":"Antwerpen",
"attributes":{"firmware":""}}}]"
是否有可能删除[{"value":
并明显在最后}]
关闭它并将其余部分保留原样?我尝试取消设置"value"
,但这实际上删除了我理解为什么的一切。但如果有一个解决方法我会很感激!
我希望如此:
{
"api_rev":"1.0",
"type":"router",
"hostname":"Router Hasselt",
"lat":50.9307,
"lon":5.33248,
"elev":50,
"aliases":[
{
"type":"wired",
"alias":"11.96.253.9"
}],
"community":"Antwerpen",
"attributes":{"firmware":""}}"
答案 0 :(得分:2)
例如,你有这个:
$json = json_decode("your stuff");
然后你做:
$json = $json[0]->value;
然后你可以把它编码回来:
$str = json_encode($json);
答案 1 :(得分:0)
试试这个,
<?php
$str='[
{"value": {
"api_rev":"1.0",
"type":"router",
"hostname":"Router Hasselt",
"lat":50.9307,
"lon":5.33248,
"elev":50,
"aliases":[
{
"type":"wired",
"alias":"11.96.253.9"
}],
"community":"Antwerpen",
"attributes":{"firmware":""}}}]';
$json=json_decode($str);
echo json_encode($json[0]->value);
?>
在此测试:DEMO
答案 2 :(得分:0)
这可能会有所帮助:)
$obj = json_decode($json);
echo json_encode($obj[0]->value);