php使用json_decode后数字对象转换成了科学计数法的解决方法
发表于:2023-01-16 14:45:34浏览:190次
总结
若值是整型,则使用
json_decode($json, true , 512 , JSON_BIGINT_AS_STRING)
若值是浮点型,则无解
若值是字符串型,则使用
json_decode($json, true)
示例
$str1 = '{"price":112233445566778899112233}';
// 使用:json_decode($str1, true)
// 输出:
// Array
// (
// [price] => 1.1223344556678E+23
// )
// 使用:json_decode($str1, true , 512 , JSON_BIGINT_AS_STRING)
// 输出:
// Array
// (
// [price] => 112233445566778899112233
// )
$str2 = '{"price":112233445566778899112233.85}';
// 使用:json_decode($str2, true)
// 输出:
// Array
// (
// [price] => 1.1223344556678E+23
// )
// 使用:json_decode($str2, true , 512 , JSON_BIGINT_AS_STRING)
// 输出:
// Array
// (
// [price] => 1.1223344556678E+23
// )
$str3 = '{"price":"112233445566778899112233.85"}';
// 使用:json_decode($str3, true)
// 输出:
// Array
// (
// [price] => 112233445566778899112233.85
// )
// 使用:json_decode($str3, true , 512 , JSON_BIGINT_AS_STRING)
// 输出:
// Array
// (
// [price] => 112233445566778899112233.85
// )
栏目分类全部>