Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet使用apollo的时候 发布配置项是json格式的数据,但是请求这个配置的时候获取数据乱码 #241

Closed
zhao-jing-hui opened this issue Apr 15, 2024 · 5 comments

Comments

@zhao-jing-hui
Copy link

zhao-jing-hui commented Apr 15, 2024

出现好多\u0022 而且不是json数据了 DbConfiguration配置的值未JSON类型,返回的信息中是字符串
image

61d11639556df6bd5b9594855632a95f

Copy link

dosubot bot commented Apr 15, 2024

To address the issue of garbled JSON formatted configuration items when fetched using Apollo in a .NET application, consider the following targeted steps:

  1. Check Content-Type: Ensure the server sets the Content-Type header to application/json to help the browser interpret the fetched content correctly.

  2. Verify Character Encoding: Confirm that the character encoding is set to UTF-8 on both the server-side and within the HTML meta tags to prevent encoding issues.

  3. Debug Minified Code: Utilize source maps in your development environment to debug minified JavaScript, allowing you to map the code back to its original source for easier issue identification.

  4. Inspect Network Traffic: Use the browser's developer tools to inspect the network traffic and check the raw response from the server, ensuring the JSON is not garbled before client-side processing.

  5. Review Apollo Client Configuration: If using Apollo Client in the .NET backend, ensure its configuration is correctly set up to handle JSON content types and review its interaction with the server or response caching.

  6. Server-Side Checks: Ensure Apollo Server with .NET correctly returns JSON objects without inadvertent modification or corruption before sending to the client.

If these steps do not resolve the issue, providing more details about the exact error message or behavior observed, along with the structure of the garbled JSON object, will help in identifying a more specific solution.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@zhao-jing-hui zhao-jing-hui reopened this Apr 15, 2024
@nobodyiam
Copy link
Member

  1. 配置返回的是 string,在 client 端根据自己的需要做转换
  2. \u0022 应该是原始配置中就有的,可以复制出来查看下

@zhao-jing-hui
Copy link
Author

  1. 配置返回的是 string,在 client 端根据自己的需要做转换
  2. \u0022 应该是原始配置中就有的,可以复制出来查看下

上午好:经过检查确认,原始配置中配置的是正确的json格式
另外我们使用的是官方提供的SDK自动请求的,用client客户端手动转换,需要改动多处代码
使用框架为以下内容
.net6.0框架
nuget包:Com.Ctrip.Framework.Apollo.Configuration
注入代码:
host.ConfigureAppConfiguration(app => app
.AddApollo(configuation.GetSection("apollo"))
);
这个是程序启动入口,直接注入apollo的配置,由sdk自动完成请求并注入程序配置

@zhao-jing-hui
Copy link
Author

  1. 配置返回的是 string,在 client 端根据自己的需要做转换
  2. \u0022 应该是原始配置中就有的,可以复制出来查看下

上午好:经过检查确认,原始配置中配置的是正确的json格式 另外我们使用的是官方提供的SDK自动请求的,用client客户端手动转换,需要改动多处代码 使用框架为以下内容 .net6.0框架 nuget包:Com.Ctrip.Framework.Apollo.Configuration 注入代码: host.ConfigureAppConfiguration(app => app .AddApollo(configuation.GetSection("apollo")) ); 这个是程序启动入口,直接注入apollo的配置,由sdk自动完成请求并注入程序配置
57cc8b14f1dd75ad9752268887a01aa3
这个是程序启动入口,直接注入apollo的配置,由sdk自动完成请求并注入程序配置

@nobodyiam nobodyiam transferred this issue from apolloconfig/apollo Apr 20, 2024
@nobodyiam
Copy link
Member

duplicated with #240

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants