我应该选择哪种格式在 C# 中请求 API - JSON 或 XML [英] Which format should I choose to request API in C# - JSON or XML

查看:16
本文介绍了我应该选择哪种格式在 C# 中请求 API - JSON 或 XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 C# 中的 REST API 请求数据.API 以 JSON 和 XML 格式为我提供相同的数据.

I'm requesting data from a REST API in C#. The API offers me the same data in a JSON and XML format.

我应该去哪一个?很清楚我会在 JavaScript 中选择哪个.但是在 C# 中是什么?是否有任何性能优势可以帮助我在 C# 中选择一种或任何良好的实践原因?

For which one should I go? It's clear which one I would choose in JavaScript. But what in C#? Are there any performance benefits to help me choose one over the other in C# or any good-practice reasons?

提前致谢!

推荐答案

就我个人而言,我会尝试这两种方法,测量性能,比较并选择更快的一个.从您的应用程序逻辑角度来看,这应该无关紧要,因为它将操作对象(不是 XML,也不是 JSON).XML/JSON 到对象的转换应该被抽象到一个存储库中,如果你觉得你最初选择的一个实现很慢或者它不起作用,你可以在眨眼间用另一种实现代替你.

Personally I would try both, measure the performance, compare and choose the one that's faster. From your application logic perspective this shouldn't really matter as it will be manipulating objects (not XML, nor JSON). The conversion of the XML/JSON to objects should be abstracted away into a repository which you could, within a blink of an eye, substitute with another implementation if you feel that the one you have chosen initially is slow or it doesn't work for you.

这篇关于我应该选择哪种格式在 C# 中请求 API - JSON 或 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆