简体   繁体   中英

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.

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.

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 :

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:

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.

For more information, head to 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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