Answer the question
In order to leave comments, you need to log in
How to display a string in Java containing special. characters?
I use Talend ESB to upload the price list from the program (Firebird database) to the site. in the site database (MySQL) in one field there should be a line like
'{\n "metadata.title": "",\n "metadata.description": "",\n "metadata.keywords": "",\n "metadata.robots": "",\n "metadata .author": "",\n "config.enable_comments": 1,\n "config.primary_category": 205,\n "jbzoo.no_index": 0\n}'' , where else do I need to insert my values (row1.DESCR) from Firebird,
"metadata.description": "row1.DESCR"from request.
Answer the question
In order to leave comments, you need to log in
That is, in essence, you need json. Why do you create it with your hands and suffer with shielding.
When you can make a java class with the fields you need, initialize it with the necessary parameters and get a json string from it, which you can send wherever you need.
Use Google's gson library - https://code.google.com/p/google-gson/
For example:
Let's make a class:
public class TalentESBData {
@SerializedName("metadata.title")
private String metadataTitle;
@SerializedName("metadata.description")
private String metadataDescription;
@SerializedName("metadata.keywords")
private String metadataKeywords;
@SerializedName("metadata.robots")
private String metadataRobots;
@SerializedName("metadata.author")
private String metadataAuthor;
@SerializedName("config.enable_comments")
private int configEnableComments;
@SerializedName("config.primary_category")
private int configPrimaryCategory;
@SerializedName("jbzoo.no_index")
private int jbzooNoIndex;
// Геттеры и сеттеры опустим их любая ide сгенерирует...
public String toJson(){
Gson gson = new Gson(); //библиотека для генерации json
String jsonResponse = gson.toJson(this);
return jsonResponse;
}
}
public class TalentMain {
public static void main(String[] args) {
TalentESBData talentData = new TalentESBData(); //инициализируем класс
talentData.setMetadataDescription(""); //заполняем поля какие надо
talentData.setMetadataAuthor("");
talentData.setMetadataKeywords("");
talentData.setMetadataRobots("");
talentData.setMetadataTitle("");
talentData.setConfigEnableComments(1);
talentData.setConfigPrimaryCategory(205);
talentData.setJbzooNoIndex(0);
System.out.println(talentData.toJson()); // Получаем json и выводим в консоль, в вашем случа
// вместо консоли можете отправлять эти данные или что там нужно сними делать.
}
}
{
"metadata.title": "",
"metadata.description": "",
"metadata.keywords": "",
"metadata.robots": "",
"metadata.author": "",
"config.enable_comments": 1,
"config.primary_category": 205,
"jbzoo.no_index": 0
}
Judging by the text of the error, you have a problem with the request. The text "insert ";" to complete the Statemen" is very similar to the errors that the database issues when the query is not correctly composed.
I read a couple of hours about escaping special characters in Java. changed the line to:
result:
'\{"metadata.title": "",
"metadata.description": " 'Терапевт – лікар'",
"metadata.keywords": "",
"metadata.robots": "",
"metadata.author": "",
"config.enable_comments": 1,
"config.primary_category": 205,
"jbzoo.no_index": 0
\}'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question