简体   繁体   English

在 GraphQL 中处理来自数据模式的特殊字符

[英]Dealing with special characters from data schema in GraphQL

I am dealing with data which is structured (by a third party) with special characters;我正在处理(由第三方)使用特殊字符构造的数据; like so:像这样:


"pageFansGenderAge": {
      "current": {
        "U.13-17": 1,
        "U.55-64": 246,
        "M.55-64": 11925,
        "U.35-44": 370,
        "F.45-54": 16443,
        "M.18-24": 8996,
        "M.35-44": 20641,
        "F.25-34": 11687,
        "U.65+": 148,
        "U.18-24": 42,
        "M.25-34": 22341,
        "F.13-17": 177,
        "U.45-54": 415,
        "F.65+": 5916,
        "F.55-64": 12172,
        "M.13-17": 141,
        "M.65+": 6576,
        "F.35-44": 14491,
        "U.25-34": 178,
        "M.45-54": 17979,
        "F.18-24": 5787
      },

GraphQL is throwing errors as it can't accept special characters, the full-stop and the hyphen are causing issues. GraphQL 抛出错误,因为它不能接受特殊字符,句号和连字符会导致问题。 Is there a known way to parse these in to stop the errors?有没有一种已知的方法来解析这些以阻止错误? Simply removing all the special characters (obvs) just returns null values.简单地删除所有特殊字符(obvs)只会返回 null 值。

Thanks in advance.提前致谢。

I have found a work around.我找到了解决办法。

I can return the current data as JSON.我可以将当前数据返回为 JSON。 Thanks to this stack-overflow answer:感谢这个堆栈溢出答案:

Answer: Use 'scalar JSON' in your GraphQL query答案:在您的 GraphQL 查询中使用“标量 JSON”

GraphQL - Get all fields from nested JSON object GraphQL - 从嵌套的 JSON object 中获取所有字段

在此处输入图像描述 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM