将Fedex的JSON模式转换为C#对象

huangapple go评论57阅读模式
英文:

Convert Fedex json schema to C# objects

问题

I'm fighting with the converting json schema from Fedex Ship API to c# objects, which can be downloaded here: https://developer.fedex.com/api/en-us/catalog/ship/docs.html

我正在尝试将Fedex Ship API的JSON模式转换为C#对象,可以在此处下载:https://developer.fedex.com/api/en-us/catalog/ship/docs.html

I tried some online tools, NJsonSchema.CodeGeneration and also many topics here like this: https://stackoverflow.com/questions/6358745/generate-c-sharp-classes-from-json-schema but actually nothing worked for me. I noticed, the Fedex schema doesn't look like example json schema in many topics. I'm not sure if I'm missing something, or why do they have different schema? Because then it's not possible to convert it in the usual way.

我尝试了一些在线工具,例如NJsonSchema.CodeGeneration,还参考了许多类似这样的主题:https://stackoverflow.com/questions/6358745/generate-c-sharp-classes-from-json-schema,但实际上都没有对我起作用。我注意到,Fedex的模式在许多主题中看起来不像示例JSON模式。我不确定我是否漏掉了什么,或者为什么它们有不同的模式?因为这样就无法以通常的方式进行转换。

At the end I had to withdraw "schemas" part from their json schema and finally I was able to create c# objects. However, they were still somehow not valid -> it was crashing when I tried to parse Response. My final solution was to manually get response result and I converted it as clean json (not json schema anymore) to c# objects.

最后,我不得不从他们的JSON模式中删除了“schemas”部分,最终我能够创建C#对象。然而,它们仍然在某种程度上无效->在尝试解析响应时出现崩溃。我的最终解决方案是手动获取响应结果,并将其转换为干净的JSON(不再是JSON模式)到C#对象。

I would like to know if I'm doing something wrong, or if there exists some better approach, how to get c# objects from their json schema.

我想知道我是否做错了什么,或者是否存在更好的方法来从他们的JSON模式中获取C#对象。

英文:

I'm fighting with the converting json schema from Fedex Ship API to c# objects, which can be downloaded here: https://developer.fedex.com/api/en-us/catalog/ship/docs.html

I tried some online tools, NJsonSchema.CodeGeneration and also many topics here like this: https://stackoverflow.com/questions/6358745/generate-c-sharp-classes-from-json-schema but actually nothing worked for me. I noticed, the Fedex schema doesn't look like example json schema in many topics. I'm not sure if I'm missing something, or why do they have different schema? Because then it's not possible to convert it in usual way.

At the end I had to withdraw "schemas" part from their json schema and finally I was able to create c# objects. However, they were still somehow not valid -> it was crashing when I tried to parse Response. My final solution was to manually get response result and I converted it as clean json (not json schema anymore) to c# objects.

I would like to know, if I'm doing something wrong, or if exists some better approach, how to get c# objects from their json schema.

答案1

得分: 0

根据我问题下面的评论,我在微软官方网站上找到了5种从开放API JSON模式获取C#对象的官方方法:https://learn.microsoft.com/sk-sk/aspnet/core/tutorials/getting-started-with-nswag?view=aspnetcore-2.0&tabs=visual-studio#code-generation-1

在我们的项目中,我们决定使用Visual Studio中的连接服务方法。我将来自FedEx的给定JSON模式放入我们的解决方案中,然后将该文件的路径链接到连接的服务中。

将Fedex的JSON模式转换为C#对象

英文:

Based on comment below my question I found out in official Microsoft site, there are 5 official approaches how to get c# object from open api json schema: https://learn.microsoft.com/sk-sk/aspnet/core/tutorials/getting-started-with-nswag?view=aspnetcore-2.0&tabs=visual-studio#code-generation-1

In our project we decided for approach using connected service in Visual Studio. I put given json schema from FedEx to our solution and then linked the path to that file into connected service.

将Fedex的JSON模式转换为C#对象

huangapple
  • 本文由 发表于 2023年6月12日 17:03:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76455077.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定