小编Rah*_*ani的帖子

将 String 转换为 Json 以应用 JSON Patch

我正在尝试使用 postmon 获取 json 字符串的请求来应用 json 补丁。问题是我无法将字符串转换为 json,数据是通过变量发布的。每次我这样做

JSON.parse(document);
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

SyntaxError: Unexpected token ' in JSON at position 1
Run Code Online (Sandbox Code Playgroud)

我发送的数据如下

{"document":"{'baz': 'qux', 'foo': 'bar'}"}
Run Code Online (Sandbox Code Playgroud)

通过邮递员使用 post 方法。

我正在使用 req.body 来获取发布数据

javascript json node.js express

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

如何在 Node JS 中生成并验证给定字符串的校验和

我正在尝试在 Node Js 中重写以下函数,以生成校验和并验证支付交易,而且我对在 Node Js 中编写代码还很陌生。

我已经从服务提供者那里获得了代码,我需要将其转换为 Node Js。我使用 Express 作为我的后端。

    <?php

    function generateChecksum($transId,$sellingCurrencyAmount,$accountingCurrencyAmount,$status, $rkey,$key)
    {   
        $str = "$transId|$sellingCurrencyAmount|$accountingCurrencyAmount|$status|$rkey|$key";
        $generatedCheckSum = md5($str);
        return $generatedCheckSum;
    }

    function verifyChecksum($paymentTypeId, $transId, $userId, $userType, $transactionType, $invoiceIds, $debitNoteIds, $description, $sellingCurrencyAmount, $accountingCurrencyAmount, $key, $checksum)
    {
        $str = "$paymentTypeId|$transId|$userId|$userType|$transactionType|$invoiceIds|$debitNoteIds|$description|$sellingCurrencyAmount|$accountingCurrencyAmount|$key";
        $generatedCheckSum = md5($str);
//      echo $str."<BR>";
//      echo "Generated CheckSum: ".$generatedCheckSum."<BR>";
//      echo "Received Checksum: ".$checksum."<BR>";
        if($generatedCheckSum == $checksum)
            return true ;
        else
            return false ;
    }   
?>
Run Code Online (Sandbox Code Playgroud)

如何在 Javascript 中编写以下代码并传递参数。

javascript node.js express

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

标签 统计

express ×2

javascript ×2

node.js ×2

json ×1