How to JSON escape in C# ?

Perfecto

Client
Регистрация
06.08.2013
Сообщения
94
Благодарностей
5
Баллы
8
Hi,

I know I can escape like this :

But I have a lot of string to escape so if someone know how to JSON escape in C# ?
 

BAZAg

Client
Регистрация
08.11.2015
Сообщения
1 787
Благодарностей
2 453
Баллы
113
You write what you want.
What is the input data?
What data do you want to get out?
 

morpheus93

Client
Регистрация
25.01.2012
Сообщения
1 058
Благодарностей
244
Баллы
63
try escaping by:

@"Your JSON data string"
 

BAZAg

Client
Регистрация
08.11.2015
Сообщения
1 787
Благодарностей
2 453
Баллы
113
C#:
object ob = new{ data = "hello"};

string json = Global.ZennoLab.Json.JsonConvert.SerializeObject(ob);
project.SendInfoToLog(json);

json = Global.ZennoLab.Json.JsonConvert.SerializeObject(json);
project.SendInfoToLog(json);
93429
 
  • Спасибо
Реакции: impul5e и myndeswx

Perfecto

Client
Регистрация
06.08.2013
Сообщения
94
Благодарностей
5
Баллы
8

Perfecto

Client
Регистрация
06.08.2013
Сообщения
94
Благодарностей
5
Баллы
8

Perfecto

Client
Регистрация
06.08.2013
Сообщения
94
Благодарностей
5
Баллы
8
C#:
object ob = new{ data = "hello"};

string json = Global.ZennoLab.Json.JsonConvert.SerializeObject(ob);
project.SendInfoToLog(json);

json = Global.ZennoLab.Json.JsonConvert.SerializeObject(json);
project.SendInfoToLog(json);
Посмотреть вложение 93429
This fonction will escape all illegal json characteres ? Can I put several input variable ?
This is not the first time you have helped me. Thanks for your help
 

BAZAg

Client
Регистрация
08.11.2015
Сообщения
1 787
Благодарностей
2 453
Баллы
113
I need to send content via REST API WordPress
I need to escape all json illegal characteres : https://www.tutorialspoint.com/json_simple/json_simple_escape_characters.htm
C#:
string line = "Text with special character /\"\'\b\f\t\r\n.";
line = Regex.Escape(line);
return line;
93437

This fonction will escape all illegal json characteres ? Can I put several input variable ?
This is not the first time you have helped me. Thanks for your help
In my answer, an example of how you can generate JSON, where you can substitute data from your variables. And then C# will take care of generating a valid JSON text.

Because of this, I asked at the very beginning what data you will submit to the input of the program, and in what form you want to get the result.
It is enough just to provide an example of the result that needs to be generated in a txt file - and I would help you generate valid JSON.
 

Perfecto

Client
Регистрация
06.08.2013
Сообщения
94
Благодарностей
5
Баллы
8
Thanks for your help, what is the syntax if I want to escape several variables without merging them
I'm pretty sure it's not that:
C#:
string line = project.Variables["variable1"].Value;
line = Regex.Escape(line);
return line;
string line = project.Variables["variable2"].Value;
line = Regex.Escape(line);
return line;
 

BAZAg

Client
Регистрация
08.11.2015
Сообщения
1 787
Благодарностей
2 453
Баллы
113
Thanks for your help, what is the syntax if I want to escape several variables without merging them
I'm pretty sure it's not that:
C#:
string line = project.Variables["variable1"].Value;
line = Regex.Escape(line);
return line;
string line = project.Variables["variable2"].Value;
line = Regex.Escape(line);
return line;
C#:
project.Variables["variable1"].Value = Regex.Escape(project.Variables["variable1"].Value);
project.Variables["variable2"].Value = Regex.Escape(project.Variables["variable2"].Value);
 

Perfecto

Client
Регистрация
06.08.2013
Сообщения
94
Благодарностей
5
Баллы
8

Perfecto

Client
Регистрация
06.08.2013
Сообщения
94
Благодарностей
5
Баллы
8

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)