I receive this response from a POST request using $.ajax():

{"command": 6,"log_size":50,"log":[
    {"type": 30,"tag": "*NETEVENT*","sensors": "0D","ti": 1047161877,"to": 0},
    {"type": 30,"tag": " __START__","sensors": "00","ti": 0000011410,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0A","ti": 0000011411,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0B","ti": 0000011411,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0D","ti": 0000011412,"to": 0},
    {"type": 30,"tag": " __START__","sensors": "00","ti": 1047215799,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0A","ti": 1047215799,"to": 0},
    {"type": 30,"tag": " __START__","sensors": "00","ti": 1047218051,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0D","ti": 0000002598,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0B","ti": 1047068795,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0D","ti": 1047068796,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0A","ti": 1047071223,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0B","ti": 1047071224,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0D","ti": 1047071225,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0A","ti": 0000000010,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0D","ti": 0000000012,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0C","ti": 1047130533,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0A","ti": 0000000026,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0A","ti": 0000000180,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0B","ti": 0000000206,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "09","ti": 0000000212,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "08","ti": 0000000383,"to": 0},
    {"type": 30,"tag": " __START__","sensors": "00","ti": 0000001562,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0A","ti": 0000001563,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0B","ti": 0000001564,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0D","ti": 1047161632,"to": 0},
    {"type": 30,"tag": " __START__","sensors": "00","ti": 1047161875,"to": 0},
    {"type": 30,"tag": "*NETEVENT*","sensors": "0B","ti": 1047161876,"to": 0}
],
"response":"ok"}

For IE works fine, in Chrome appears "Syntax error: unexpected number" and in Firefox the message is "SyntaxError: JSON.parse: expected ',' or '}' after property value in object"

In various online JSON parsers and validators the format of the response seems to be OK, but in firefox and chrome not works.

知道为什么会这样吗?

推荐答案

A number can't start with a not significative 0.

无效:"ti": 0000011410

From JSON.org :

在此处输入图像描述

您应该在源代码中修复它,但是如果您不能,assuming your JSON is always similar to this one(字符串中没有数字),那么您可能可以使用正则表达式来修复它:

var obj = JSON.parse(str.replace(/ 0+(?![\. }])/g, ' '));

You can't even here use the evil eval because "0000011410" would be parsed as a octal :

console.log(eval('({"ti": 0000011410})'));

outputs

{ti: 4872}

这可能解释了为什么在JSON中禁止以无意义的0开头的数字被认为更安全.

Json相关问答推荐

如何在Power BI中集成API和JSON数据后将数据转换为表?

Golang JSON Date Tim.Date()测试请求

最新版本的Deneb在数据溢出时不支持滚动

使用Jolt库对多个数组进行嵌套循环

如何将加权边列表导出到JSON树?

VBA json按特定属性名称提取所有数据

Jolt-Json转换:通过引用标识符(而不是索引)设置值

当 JSON 字段名称有空格时,ABAP 中的 JSON 反序列化

匹配来自不同数组的值

如何在 Apps 脚本中循环遍历 JSON 响应

转义 Haskell 记录的字段

从 PySpark 中的复杂 JSON 文件中高效清除 HTML 实体

如何使用 React 从 NASA IMAGES API 中解构所需信息

如何让 JSON.NET 忽略对象关系?

杰克逊 2.0 和 Spring 3.1

是否可以将数据写入本地 json 文件,除了Angular 之外什么都没有?

ASP.NET Core API 仅返回列表的第一个结果

Django:TypeError:[] 不是 JSON 可序列化的为什么?

从 Json 对象 Android 中获取字符串值

在 .NET 中缩小缩进的 JSON 字符串