How to JSON escape in C# ?

  • Автор темы Автор темы Perfecto
  • Дата начала Дата начала

Perfecto

Client
Регистрация
06.08.2013
Сообщения
108
Реакции
9
Баллы
18
Hi,

I know I can escape like this :
EZbnjmU.png

But I have a lot of string to escape so if someone know how to JSON escape in C# ?
 
You write what you want.
What is the input data?
What data do you want to get out?
 
try escaping by:

@"Your JSON data string"
 
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
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
 
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.
 
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;
 
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);
 

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