【问题标题】:An error occurred while converting the transformed value to JSON. The transformed value is not a valid JSON将转换后的值转换为 JSON 时出错。转换后的值不是有效的 JSON
【发布时间】:2021-10-27 01:35:39
【问题描述】:

我在 Azure 逻辑应用步骤的输出中显示一个错误,该错误的操作类型为“Transform_JSON_to_JSON”(我用来转换某些 JSON 的 Liquid 转换)。我没有看到导致错误的原因?

液体动作的输入如下。此格式为有效 JSON

[{"DeviceType":"Scanner","Code":"ABC","CustomerId":null,"FirstName":"John","LastName":"Doe","TransactionType":"Actionable","TransactionSubTypes":["ScanFailed"],"Message":"Scan failed.","Data":null,"Status":"Pending","Text":null,"AgentId":null,"AgentName":null,"NodeId":"12345","Timestamp":"2021-10-26T22:43:37.695759+00:00","UTCTimeStamp":"2021-10-26T22:43:37.695763Z"}]

液体模板为:

[
    {% for transaction in content %}
      {
        "DeviceType": "{{content.DeviceType}}",
        "Code": "{{content.Code}}"
      }
    {% endfor %}
]

Azure 逻辑应用设计器中的流操作的原始输出是

"{\"StatusCode\":400,\"ErrorCode\":18,\"Details\":null,\"Message\":\"An error occurred while converting the transformed value to JSON. The transformed value is not a valid JSON. 'After parsing a value an unexpected character was encountered: {. Path '[0]', line 8, position 6.'\",\"Data\":{},\"InnerException\":{\"ClassName\":\"Newtonsoft.Json.JsonReaderException\",\"Message\":\"After parsing a value an unexpected character was encountered: {. Path '[0]', line 8, position 6.\",\"Data\":null,\"InnerException\":null,\"HelpURL\":null,\"StackTraceString\":\"   at Newtonsoft.Json.JsonTextReader.ParsePostValue(Boolean ignoreComments)\\r\\n   at Newtonsoft.Json.JsonTextReader.Read()\\r\\n   at Newtonsoft.Json.Linq.JContainer.ReadContentFrom(JsonReader r, JsonLoadSettings settings)\\r\\n   at Newtonsoft.Json.Linq.JContainer.ReadTokenFrom(JsonReader reader, JsonLoadSettings options)\\r\\n   at Newtonsoft.Json.Linq.JArray.Load(JsonReader reader, JsonLoadSettings settings)\\r\\n   at Newtonsoft.Json.Linq.JToken.ReadFrom(JsonReader reader, JsonLoadSettings settings)\\r\\n   at Newtonsoft.Json.Linq.JToken.Parse(String json, JsonLoadSettings settings)\\r\\n   at Microsoft.Azure.Function.Common.BaseLiquidTransformer.ParseTransformedContent(String transformedContent, JSchema schema) in X:\\\\bt\\\\1186352\\\\repo\\\\src\\\\functions\\\\Scripts\\\\Function.Common\\\\Liquid\\\\BaseLiquidTransformer.cs:line 127\",\"RemoteStackTraceString\":null,\"RemoteStackIndex\":0,\"ExceptionMethod\":\"8\\nParsePostValue\\nNewtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed\\nNewtonsoft.Json.JsonTextReader\\nBoolean ParsePostValue(Boolean)\",\"HResult\":-2146233088,\"Source\":\"Newtonsoft.Json\",\"WatsonBuckets\":null},\"TargetSite\":{\"Name\":\"ParseTransformedContent\",\"AssemblyName\":\"Microsoft.Azure.Function.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\",\"ClassName\":\"Microsoft.Azure.Function.Common.BaseLiquidTransformer\",\"Signature\":\"Newtonsoft.Json.Linq.JToken ParseTransformedContent(System.String, Newtonsoft.Json.Schema.JSchema)\",\"Signature2\":\"Newtonsoft.Json.Linq.JToken ParseTransformedContent(System.String, Newtonsoft.Json.Schema.JSchema)\",\"MemberType\":8,\"GenericArguments\":null},\"StackTrace\":\"   at Microsoft.Azure.Function.Common.BaseLiquidTransformer.ParseTransformedContent(String transformedContent, JSchema schema) in X:\\\\bt\\\\1186352\\\\repo\\\\src\\\\functions\\\\Scripts\\\\Function.Common\\\\Liquid\\\\BaseLiquidTransformer.cs:line 133\\r\\n   at Microsoft.Azure.Function.LiquidTransform.LiquidTransformRequestProcessor.GetTransformedContentResponseMessage(HttpRequestMessage request, LiquidTransformKind transformKind, String transformedContent, JSchema outputSchema) in X:\\\\bt\\\\1186352\\\\repo\\\\src\\\\functions\\\\Scripts\\\\Function.LiquidTransform\\\\LiquidTransformRequestProcessor.cs:line 91\\r\\n   at Microsoft.Azure.Function.LiquidTransform.LiquidTransformRequestProcessor.<ProcessRequest>d__2.MoveNext() in X:\\\\bt\\\\1186352\\\\repo\\\\src\\\\functions\\\\Scripts\\\\Function.LiquidTransform\\\\LiquidTransformRequestProcessor.cs:line 60\",\"HelpLink\":null,\"Source\":\"Microsoft.Azure.Function.Common\",\"HResult\":-2146233088}"

【问题讨论】:

    标签: json liquid azure-logic-apps dotliquid


    【解决方案1】:

    我缺少逗号来分隔输出数组中的每个 JSON 对象文字(并且还在循环中引用了不正确的变量来获取每个项目的属性)。正确的液体模板是:

    [
        {% for transaction in content %}
          {
            "DeviceType": "{{transaction.DeviceType}}",
            "Code": "{{transaction.Code}}"
          },
        {% endfor %}
    ]
    

    【讨论】:

      猜你喜欢
      • 2020-01-15
      • 2019-05-07
      • 2021-07-27
      • 1970-01-01
      • 2015-10-22
      • 1970-01-01
      • 2022-09-27
      • 2018-05-27
      • 2020-05-05
      相关资源
      最近更新 更多