解析带有未定义值的JSON吗? [英] Parse JSON with undefined value?

查看:65
本文介绍了解析带有未定义值的JSON吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复::解析或修复具有特殊未定义"值的JSON?

我想知道是否可以解析类似
javascript JSON.parse('{ "name": undefined}');的内容 是由API生成的?

I would like to know if it's possible to parse something like
javascript JSON.parse('{ "name": undefined}'); generated by the API?

以上代码错误.

是否有某种解析方式? -我的实际示例是很多更长(请参见此处),我只是使用出于说明目的的简短示例

Is there some way of parsing it? - my actual example is much longer (see here), I just use the very short example for illustrative purposes

注意:

  • 此处是实际JSON来自的页面
  • 此处是原始JSON的更改版本,将Single Column Serp v3替换为Single undefined Column Serp v3,因此字符串值包含undefined(作为字符串),使任何可靠的gsub更加困难
  • Here is the page the actual JSON is from
  • Here is an altered version of the original JSON that replaces Single Column Serp v3 with Single undefined Column Serp v3, so that a string value contains undefined (as a string), making any reliable gsub more difficult

推荐答案

无法解析具有未定义值的JSON; undefined是特殊的.实际上,undefined作为值"一定不能出现在有效的JSON中.该错误可能发生在JSON生成器上.

You cannot parse a JSON with an undefined value; undefined is special. In fact, undefined as a "value" must not occur in valid JSON. The error might have happened on the JSON generator instead.

官方资料, JSON数据 交换语法,指出

The official source, The JSON Data Interchange Syntax, states that

JSON值可以是对象,数组,数字,字符串,true,false或null.

A JSON value can be an object, array, number, string, true, false, or null.

最好的解决方法是检查JSON生成器,以及为什么它在JSON中生成未定义的内容.

The best remedy is to examine the JSON generator and why it generates undefined in a JSON.

这篇关于解析带有未定义值的JSON吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆