I'm new to json. I have existing json data in a file. here it looks like:
{
"qwqw":{
"id":3,
"item1":{
"id":15,
"price":31.85
},
"item2":{
"id":17,
"price":26
},
"item3":{
"id":16,
"price":57.85
}
}
}
I can get this value using json_decode. I will add another entry using this code.
$data = json_decode( file_get_contents('test.ini'), true );
$data[] = array(
'id'=>4,
'item1'=>array(
'id'=>15,
'price'=>11
),
'item2'=>array(
'id'=>17,
'price'=>12
),
'item3'=>array(
'id'=>16,
'price'=>13.50
)
);
file_put_contents('test.ini', json_encode($data) );
This works properply. When I decoded it again. this how it looks.
{
"qwqw":{
"id":3,
"item1":{
"id":15,
"price":31.85
},
"item2":{
"id":17,
"price":26
},
"item3":{
"id":16,
"price":57.85
}
},
"0":{
"id":3,
"item1":{
"id":15,
"price":11
},
"item2":{
"id":17,
"price":12
},
"item3":{
"id":16,
"price":13.5
}
}
}
My problem is, can I change the value "0" ? to a string.
anyone who can help ?