基本信息
源码名称:JSON 格式化工具源码
源码大小:2.07M
文件格式:.zip
开发语言:C#
更新时间:2015-11-25
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
JSON 格式化
JSON 格式化
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using EPocalipse.Json.Viewer;
using System.IO;
namespace EPocalipse.Json.JsonView
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void MainForm_Shown(object sender, EventArgs e)
{
string[] args = Environment.GetCommandLineArgs();
for (int i = 1; i < args.Length; i )
{
string arg = args[i];
if (arg.Equals("/c", StringComparison.OrdinalIgnoreCase))
{
LoadFromClipboard();
}
else if (File.Exists(arg))
{
LoadFromFile(arg);
}
}
}
private void LoadFromFile(string fileName)
{
string json = File.ReadAllText(fileName);
JsonViewer.ShowTab(Tabs.Viewer);
JsonViewer.Json = json;
}
private void LoadFromClipboard()
{
string json = Clipboard.GetText();
if (!String.IsNullOrEmpty(json))
{
JsonViewer.ShowTab(Tabs.Viewer);
JsonViewer.Json = json;
}
}
private void MainForm_Load(object sender, EventArgs e)
{
JsonViewer.ShowTab(Tabs.Text);
}
/// <summary>
/// Closes the program
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks>Menu item File > Exit</remarks>
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
/// <summary>
/// Open File Dialog for Yahoo! Pipe files or JSON files
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks>Menu item File > Open</remarks>
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter =
"Yahoo! Pipe files (*.run)|*.run|json files (*.json)|*.json|All files (*.*)|*.*";
dialog.InitialDirectory = Application.StartupPath;
dialog.Title = "Select a JSON file";
if (dialog.ShowDialog() == DialogResult.OK)
{
this.LoadFromFile(dialog.FileName);
}
}
/// <summary>
/// Launches About JSONViewer dialog box
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks>Menu item Help > About JSON Viewer</remarks>
private void aboutJSONViewerToolStripMenuItem_Click(object sender, EventArgs e)
{
new AboutJsonViewer().ShowDialog();
}
/// <summary>
/// Selects all text in the textbox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks>Menu item Edit > Select All</remarks>
private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
{
Control c;
c = this.JsonViewer.Controls.Find("txtJson", true)[0];
((TextBox)c).SelectAll();
}
/// <summary>
/// Deletes selected text in the textbox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks>Menu item Edit > Delete</remarks>
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
Control c;
c = this.JsonViewer.Controls.Find("txtJson", true)[0];
string text;
if (((TextBox)c).SelectionLength > 0)
text = ((TextBox)c).SelectedText;
else
text = ((TextBox)c).Text;
((TextBox)c).SelectedText = "";
}
/// <summary>
/// Pastes text in the clipboard into the textbox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks>Menu item Edit > Paste</remarks>
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
Control c;
c = this.JsonViewer.Controls.Find("txtJson", true)[0];
((TextBox)c).Paste();
}
/// <summary>
/// Copies text in the textbox into the clipboard
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks>Menu item Edit > Copy</remarks>
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
Control c;
c = this.JsonViewer.Controls.Find("txtJson", true)[0];
((TextBox)c).Copy();
}
/// <summary>
/// Cuts selected text from the textbox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks>Menu item Edit > Cut</remarks>
private void cutToolStripMenuItem_Click(object sender, EventArgs e)
{
Control c;
c = this.JsonViewer.Controls.Find("txtJson", true)[0];
((TextBox)c).Cut();
}
/// <summary>
/// Undo the last action
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks>Menu item Edit > Undo</remarks>
private void undoToolStripMenuItem_Click(object sender, EventArgs e)
{
Control c;
c = this.JsonViewer.Controls.Find("txtJson", true)[0];
((TextBox)c).Undo();
}
/// <summary>
/// Displays the find prompt
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks>Menu item Viewer > Find</remarks>
private void findToolStripMenuItem_Click(object sender, EventArgs e)
{
Control c;
c = this.JsonViewer.Controls.Find("pnlFind", true)[0];
((Panel)c).Visible = true;
Control t;
t = this.JsonViewer.Controls.Find("txtFind", true)[0];
((TextBox)t).Focus();
}
/// <summary>
/// Expands all the nodes
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks>Menu item Viewer > Expand All</remarks>
/// <!---->
private void expandAllToolStripMenuItem_Click(object sender, EventArgs e)
{
Control c;
c = this.JsonViewer.Controls.Find("tvJson", true)[0];
((TreeView)c).BeginUpdate();
try
{
if (((TreeView)c).SelectedNode != null)
{
TreeNode topNode = ((TreeView)c).TopNode;
((TreeView)c).SelectedNode.ExpandAll();
((TreeView)c).TopNode = topNode;
}
}
finally
{
((TreeView)c).EndUpdate();
}
}
/// <summary>
/// Copies a node
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks>Menu item Viewer > Copy</remarks>
private void copyToolStripMenuItem1_Click(object sender, EventArgs e)
{
Control c;
c = this.JsonViewer.Controls.Find("tvJson", true)[0];
TreeNode node = ((TreeView)c).SelectedNode;
if (node != null)
{
Clipboard.SetText(node.Text);
}
}
/// <summary>
/// Copies just the node's value
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks>Menu item Viewer > Copy Value</remarks>
/// <!-- JsonViewerTreeNode had to be made public to be accessible here -->
private void copyValueToolStripMenuItem_Click(object sender, EventArgs e)
{
Control c;
c = this.JsonViewer.Controls.Find("tvJson", true)[0];
JsonViewerTreeNode node = (JsonViewerTreeNode)((TreeView)c).SelectedNode;
if (node != null && node.JsonObject.Value != null)
{
Clipboard.SetText(node.JsonObject.Value.ToString());
}
}
}
}