【问题标题】:Google pay parsing json token谷歌支付解析json token
【发布时间】:2018-07-23 01:41:50
【问题描述】:

在尝试解析 google pay 令牌时,我在 Newtonsoft.Json.dll 异常中收到“Newtonsoft.Json.JsonReaderException”,(来自https://developers.google.com/pay/api/android/guides/resources/payment-data-cryptography#using-tink 的示例令牌)

{
    "protocolVersion":"ECv1",
    "signature":"TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ",
    "signedMessage":" {\"encryptedMessage\":\"ZW5jcnlwdGVkTWVzc2FnZQ==\",
    \"ephemeralPublicKey\":\"ZXBoZW1lcmFsUHVibGljS2V5\",
    \"tag\":\"c2lnbmF0dXJl\"}"
} 
using JSONObject.Parse()

after removing special characters i end up with the following 

 {"protocolVersion":"ECv1",
 "signature":"TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ",
 "signedMessage":" 
 {"encryptedMessage":"ZW5jcnlwdGVkTWVzc2FnZQ==",
 "ephemeralPublicKey":"ZXBoZW1lcmFsUHVibGljS2V5","tag":"c2lnbmF0dXJl"}"}

 The exception is as followed: Exception thrown: 'Newtonsoft.Json.JsonReaderException' in Newtonsoft.Json.dll

 in terms of the class being used, I cannot provide the full code as it is work related, but the following is the code where JSON is used

        googlePayXml = Regex.Replace(googlePayXml, "[^A-Za-z0-9+/=\s]", "")
        googlePayXml = Regex.Replace(googlePayXml, "\\", "")

        'Base64 decode Google Pay PaymentData'
        Dim decodedGooglePayPaymentData As String = 
        Encoding.UTF8.GetString(Convert.FromBase64String(googlePayXml))
        Dim paymentData As JObject = 
        JObject.Parse(decodedGooglePayPaymentData)

谁能告诉我格式有什么问题?

【问题讨论】:

  • 异常信息是什么?能分享一下反序列化json的代码和反序列化到的类吗?
  • 如果您能提供minimal reproducible example,那就太好了。
  • 编辑了问题
  • 那么上面的格式被破坏了,如果那是你想要解码的。请注意,signedMessage 在冒号后有一个引号。它不应该。另外,您确定除了异常类型之外没有与该异常有关的消息吗?

标签: c# json visual-studio


【解决方案1】:

就像提到的那样,示例标记的格式不正确,一旦我将括号移到外面,json.parse 就起作用了

【讨论】:

    猜你喜欢
    • 2020-10-02
    • 1970-01-01
    • 2021-11-03
    • 2020-03-02
    • 2018-02-19
    • 2021-10-07
    • 2019-02-17
    • 1970-01-01
    • 2011-10-26
    相关资源
    最近更新 更多