正则表达式获取引号之间的数字
regex get number betwen quotes
我有不同的字符串 json 在行中输入 egz 格式
{"env":"stato","usc":"00000000","isc":"000100","sn":"0120xxxxmacxxx"}
{{"cmd":"stat"},{"usc":"00000000",{"isc":"1001000"}},"sn":"0120xxxxmacxxx"}
{{"cmd":"status","usc":"00000000","isc":"1110001"},"sn":"0120xxxxmacxxx"}
{'stat':'dev',{data:['usc':'00000000','isc':'10010001']},'sn':'0120xxxxmacxxx'}
需要单个正则表达式,方法是在 "isc":" 后仅获取数字 0-1 格式的引号:"仅需要此数字" 在单个 php 正则表达式中适用于所有格式。
例如
$json = '{"env":"stato","usc":"00000000","isc":"00010000","sn":"0120xxxxmacxxx"}';
$find = "isc";
function find_data($find,$json){
preg_match('/,[{[]*["\']'.$find.'["\']:["\'](.*)["\'][}]]*,/i', $json, $r);
return $r;
}
json循环解决不来! json 搜索只能接受一行代码,
我在 atmega 16
中的计算和内存资源有限
谢谢帮助
$json = '{"env":"stato","usc":"00000000","isc":"00010000","sn":"0120xxxxmacxxx"}';
$arr = json_decode($json);
$isc = $arr->isc;
print_r($isc); // Prints: 00010000
我有不同的字符串 json 在行中输入 egz 格式
{"env":"stato","usc":"00000000","isc":"000100","sn":"0120xxxxmacxxx"}
{{"cmd":"stat"},{"usc":"00000000",{"isc":"1001000"}},"sn":"0120xxxxmacxxx"}
{{"cmd":"status","usc":"00000000","isc":"1110001"},"sn":"0120xxxxmacxxx"}
{'stat':'dev',{data:['usc':'00000000','isc':'10010001']},'sn':'0120xxxxmacxxx'}
需要单个正则表达式,方法是在 "isc":" 后仅获取数字 0-1 格式的引号:"仅需要此数字" 在单个 php 正则表达式中适用于所有格式。 例如
$json = '{"env":"stato","usc":"00000000","isc":"00010000","sn":"0120xxxxmacxxx"}';
$find = "isc";
function find_data($find,$json){
preg_match('/,[{[]*["\']'.$find.'["\']:["\'](.*)["\'][}]]*,/i', $json, $r);
return $r;
}
json循环解决不来! json 搜索只能接受一行代码, 我在 atmega 16
中的计算和内存资源有限谢谢帮助
$json = '{"env":"stato","usc":"00000000","isc":"00010000","sn":"0120xxxxmacxxx"}';
$arr = json_decode($json);
$isc = $arr->isc;
print_r($isc); // Prints: 00010000