小编jav*_*der的帖子

解析有错误的JSON并能够显示错误的位置

这不是关于如何管理或纠正错误的JSON,而是关于如何向用户解释错误在JSON中的错误.

有没有办法找出解析器失败的JSON中的哪个位置.

我想在node.js应用程序中解决此问题,因此请尽可能在该域中保留您的答案.

当我使用内置的JSON对象和错误的JSON的parse方法时,我只得到异常消息SyntaxError: Unexpected string.我想找出错误发生的位置.

首选的JSON.validate(json)是返回结果ok/error和错误位置.像这样的东西:

var faultyJsonToParse = '{"string":"value", "boolean": true"}';
var result = JSON.validate(faultyJsonToParse);
if (result.ok == true) {
   console.log('Good JSON, well done!');
} else {
   console.log('The validator found a \'' + result.error + '\' of type \'' + result.errorType + '\' in your JSON near position ' + result.position);
}
Run Code Online (Sandbox Code Playgroud)

上述想要的结果将是:

The validator found a 'SyntaxError' of type 'Unexpected string' in your JSON near position 35.
Run Code Online (Sandbox Code Playgroud)

javascript validation error-handling json node.js

9
推荐指数
1
解决办法
1万
查看次数

错误:EBADF,使用nohup永远运行节点时的错误文件描述符

我有一个问题,node.js运行一个小型Web服务器来提供文件系统中的文件.当它启动时,node server.js它就像一个魅力,但当用nohup启动它或永远node.js找不到文件.

nohup node.js forever

8
推荐指数
2
解决办法
9694
查看次数

将HTML表导入到OO Calc中作为UTF8而不转换为实体

我在OpenOffice或LibreOffice中打开HTML表时遇到问题,如果它包含ÅÄÖåäö等UTF8扩展字符.

当打开表格进入M $ Excel时,它按预期工作,但我不能让OO做同样的事情.

通过将所有扩展字符转换为其HTML实体equivalentÅ 它可以工作,但直接获得正确的字符会很好.

有谁知道我应该怎么做?

我在一个名为excelsample.xls的文件中有以下内容,如果我用OO Calc打开它,它看起来不会很好.

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta http-equiv="content-type" content="application/vnd.ms-excel" charset="UTF-8">
    <meta charset="UTF-8">
</head>
<body>
    <table>
        <tr>
            <td>Prawn sandwich</td><td>Räksmörgås</td>
        </tr>
    </table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

html-table utf-8 html-entities openoffice-calc libreoffice

5
推荐指数
1
解决办法
4278
查看次数