如何将LinqPAD中的数据导出为JSON?

编程入门 行业动态 更新时间:2024-10-11 13:21:07
本文介绍了如何将LinqPAD中的数据导出为JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想创建一个JSON文件,用作简单的Web原型制作练习的一部分. LinqPAD非常适合按我需要的形状从数据库访问数据,但是我无法很轻松地将其作为JSON导出.

I want to create a JSON file for use as part of a simple web prototyping exercise. LinqPAD is perfect for accessing the data from my DB in just the shape I need, however I cannot get it out as JSON very easily.

我实际上并不在乎模式是什么,因为我可以调整我的JavaScript以使其能够处理返回的任何内容.

I don't really care what the schema is, because I can adapt my JavaScript to work with whatever is returned.

这可能吗?

推荐答案

更流畅的解决方案是将以下方法添加到Linqpad中的我的扩展"文件中:

A more fluent solution is to add the following methods to the "My Extensions" File in Linqpad:

public static String DumpJson<T>(this T obj) { return obj .ToJson() .Dump(); } public static String ToJson<T>(this T obj) { return new System.Web.Script.Serialization.JavaScriptSerializer() .Serialize(obj); }

然后,您可以在需要的任何查询中像这样使用它们:

Then you can use them like this in any query you like:

Enumerable.Range(1, 10) .Select(i => new { Index = i, IndexTimesTen = i * 10, }) .DumpJson();

我分别添加了"ToJson",以便可以与"Expessions"一起使用.

I added "ToJson" separately so it can be used in with "Expessions".

更多推荐

如何将LinqPAD中的数据导出为JSON?

本文发布于:2023-11-30 19:27:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651226.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   数据   LinqPAD   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!