cscript jscript JSON [英] cscript jscript JSON

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

问题描述

这是一个非常非常非常奇怪的问题.

This is a very very (very!!!) strange problem.

我有一个JSCRIPT,它在名为testJSON.js的文件中使用dos CSCRIPT在Windows XP和7上运行.

I have this JSCRIPT that runs on windows XP and 7 using dos CSCRIPT in a file called testJSON.js.

if ( ! this.JSON ) WScript.Echo("JSON DOESN'T EXISTS");

而且,消息出现了,但这是JSCRIPT的意外行为,因为JSON(如

And, well, the message appear, but is an unexpected behavior of JSCRIPT because JSON (as the MSDN documentation says) is one of the default object in the JSCRIPT 5.8 and my system on Windows 7 runs exactly JSCRIPT 5.8.

现在,我已经通过创建一个新的文本文件并手动组成一个有效的JSON字符串来临时解决了这个问题(使用一个稍微复杂的脚本)(显然,即使系统没有JSCRIPT 5.8(按JSON的要求),但我主要想知道两件事:

Now, I have temporary solved this problem (in a little complex script) by creating a new text file and MANUALLY composing a valid JSON string (and, obviously this makes everything works fine even if the system doesn't have the JSCRIPT 5.8 as requested for JSON) but I like to know two things mainly:

1st 为什么即使我的JSCRIPT版本是支持该对象的版本,我也不能使用JSON对象?

1st Why I can't use the JSON object even if my JSCRIPT version is the one that supports that object?

第二个,我已经阅读了一些有关我的JSCRIPT环境中的JSON(和其他)不可用对象的启用" ,但是所有示例都是针对C#的,我想知道是否存在一些与JSCRIPT等效的代码.

2nd I have read something about the "enabling" of the JSON (and other) unavailable object in my JSCRIPT environment, but all examples is for C# and I like to know if some equivalent code for JSCRIPT exists or not.

推荐答案

为什么即使我的JSCRIPT版本是支持该对象的版本,我也不能使用JSON对象?

Why I can't use the JSON object even if my JSCRIPT version is the one that supports that object?

根据 MSDN , Windows Script Host默认使用JScript 5.7功能集,以实现向后兼容. JScript 5.8功能集仅在IE8 +标准文档模式下的Internet Explorer中使用.

According to MSDN, Windows Script Host uses the JScript 5.7 feature set by default for backward compatibility. The JScript 5.8 feature set is only used in Internet Explorer in the IE8+ Standards document modes.

您有以下选择:

  1. 在脚本中包含 json2.js .有关在JScript脚本中包含外部脚本的选项,请参见此问题.

  1. Include json2.js in your script. See this question for options for including external scripts in JScript scripts.

将注册表修改为

Modify the registry to expose IE9's JScript engine to Windows Script Host. UPD: This solution uses IE's JScript DLLs, but doesn't activate the 5.8 feature set.

创建JScript执行主机以编程方式使用Active Script界面​​,并使用 IActiveScriptProperty::SetProperty 强制执行JScr​​ipt 5.8功能集(SCRIPTLANGUAGEVERSION_5_8). 这是一个C ++示例.

Create a JScript execution host programmatically using the Active Script interfaces and use IActiveScriptProperty::SetProperty to force the JScript 5.8 feature set (SCRIPTLANGUAGEVERSION_5_8). Here's a C++ example.

我已经阅读了有关在JSCRIPT环境中启用" JSON(和其他)不可用对象的知识,但是所有示例都是针对C#的,我想知道是否存在与JSCRIPT等效的代码.

I have read something about the "enabling" of the JSON (and other) unavailable object in my JSCRIPT environment, but all examples is for C# and I like to know if some equivalent code for JSCRIPT exists or not.

只能使用具有适当COM支持的语言来创建自定义脚本执行主机,例如C ++,C#等.不能使用JScript,因为例如,它不支持out参数.

Custom script execution hosts can be created only using languages with proper COM support, such as C++, C# etc. JScript can't be used for that, because, for example, it doesn't support out parameters.

这篇关于cscript jscript JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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