我的Json编码输出类似于下面的
{
"msg_id":"14789",
"message":"dummy+message",
"msgType":"TEXT",
"sendondate":"2013-12-26 13:19:49",
"seq_id":{
"1":{
"valid":"true",
"credit":"1.00",
"linecount":1,
"billcredit":1,
"id_provider":"18",
"providerkey":"TI",
"regionKey":"CH",
"originalnumber":"11",
"validnumber":"+11",
"countryprefix":"11",
"ONLYNUMBER":"11",
"NUMBERWITHZERO":"11",
"INTERNATIONALONLY":"11",
"INTERNATIONALWITHPLUS":"+11",
"mnpID":"905",
"dlr_seq":1,
"textMessage":"dummy+message",
"status":"",
"remarks":""
}
}
}
我想打印billcredit的值作为输出。我怎么能在php中解码呢?
答案 0 :(得分:3)
试试这样:
$json = '{"foo-bar": 12345}';
$obj = json_decode($json);
print $obj->{'foo-bar'};
有关php中json的更多信息,请访问link。
答案 1 :(得分:1)
var_dump(json_decode($json));
答案 2 :(得分:0)
$your_data_in_array_comes_here = json_decode("Your Output String");
With above array you can generate html as your wish.
答案 3 :(得分:0)
这是您希望json_decode()
获得的内容$string = '{"msg_id":"14789","message":"dummy+message","msgType":"TEXT","sendondate":"2013-12-26 13:19:49","seq_id":{"1":{"valid":"true","credit":"1.00","linecount":1,"billcredit":1,"id_provider":"18","providerkey":"TI","regionKey":"CH","originalnumber":"11","validnumber":"+11","countryprefix":"11","ONLYNUMBER":"11","NUMBERWITHZERO":"11","INTERNATIONALONLY":"11","INTERNATIONALWITHPLUS":"+11","mnpID":"905","dlr_seq":1,"textMessage":"dummy+message","status":"","remarks":""}}}';
// Return Object Data
print_r( json_decode($string) );
// Return Array Data
print_r( json_decode($string, true) );
$decoded_data = json_decode($string, true);
// Bill Credit Value
echo "billcredit: " . $decoded_data['seq_id'][1]['billcredit'];