简体   繁体   English

在文本框C#表单中显示Json时出错

[英]Error displaying Json in text box C# form

I´m using Newton Json.NET to deserialize a simple Json and display the resulting string into a TextBox in a C# form. 我使用Newton Json.NET反序列化一个简单的Json,并将结果字符串显示为C#形式的TextBox

The problem is that I would like to append other data to each deserialized part. 问题是我想将其他数据附加到每个反序列化的部分。 This is the well-formed string I have that is printed in the debug terminal. 这是我在调试终端中打印的格式良好的字符串。

在此输入图像描述

BEGIN 12234 ....Homer Simpson$$$$ 123456 are all data that I appended to the Json. BEGIN 12234 ....Homer Simpson$$$$ 123456是我附加到Json的所有数据。

So far, so good. 到现在为止还挺好。 However, the data displayed on the form text box look like this: 但是,表单文本框中显示的数据如下所示: 在此输入图像描述

Note that the text is unaligned and the appended part is in wrong positions. 请注意,文本未对齐,并且附加部分位置错误。

This is the code I used to get the json : 这是我用来获取json的代码:

var DJson = JsonConvert.DeserializeObject<dynamic>(obj);

string foot = DJson[0].name.ToString();
string ret = "BEGIN 123456 " + DJson.ToString() + "...." + foot + "$$$$" + "123456";
return ret;

It looks like a right-to-left formatting problem. 它看起来像是一个从右到左的格式化问题。 Change your TextBox.RightToLeft property to RightToLeft.No as follows: TextBox.RightToLeft属性RightToLeft.NoRightToLeft.No ,如下所示:

myTextBox.RightToLeft = RightToLeft.No;

or, even better, change that property in the Winforms Designer so that this will be automatically reflected into the InitializeComponent() method. 或者更好的是,在Winforms Designer更改该属性,以便将其自动反映到InitializeComponent()方法中。

For more information, head to MSDN . 有关更多信息,请访问MSDN

Looks like your text box prints right-to-left. 看起来您的文本框从右向左打印。 Have a look at this: 看看这个:
https://msdn.microsoft.com/en-us/library/system.windows.forms.control.righttoleft(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/system.windows.forms.control.righttoleft(v=vs.110).aspx

您需要将TextBox.RightToLeftTextbox属性更改为RightToLeft.No

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM