I am trying to encode an array which contains floats and NaN into JSON string from Python using json.dumps().

But the encoded JSON string is not being decoded successfully in PHP. Is the NaN causing this problem? How can I work around this situation?

推荐答案

json.dumps has an allow_nan parameter, which defaults to True.

NaN, Infinity and -Infinity are not part of JSON, but they are standard in Javascript, so they're commonly used extensions. If the recipient can't handle them, set allow_nan=False. But then you'll get ValueError when you try to serialise NaN.

Json相关问答推荐

解析JSON说函数parse_json不存在?

在解码的JSON哈希中搜索数组元素

使用PowerShell解析文件并获取特定行的值

Pandas 对REST API的自定义响应

如何避免解析 ISuperObject 类型字段中的 json 对象

如何将一个对象添加到多个对象中 JOLT

如何使用jolt将嵌套数据变成线性数据

jq :当路径可变时更新 json 内容

如何使用 jq 将字符串数组转换为对象?

使用 TypeScript 接口时如何修复未定义错误?

从 json 数组中仅提取一个值导致 vb6

Microsoft GRAPH 查询使用端点 /deviceManagement/deviceHealthScripts 列出了一种不熟悉的检测脚本内容格式

如何使用 ConfigurationBuilder 解析现有的 json 字符串(不是文件)

如何将任意 json 对象发布到 webapi

如何使用 Jackson 注释从 HttpResponse 反序列化 JSON 对象?

MySQL Select JSON 字段属性具有值的位置

如何使用 Json.NET 反序列化可以是两种不同数据类型的 JSON 属性

如何使用 Gson 将 JSONArray 转换为 List?

js 中奇怪的 JSON 解析行为,Unexpected token :

如何遍历 JSON 中的条目?