在 Unix 服务器上:无法将货币符号(£、€)从 json 解析为 .csv 文件
On Unix server: unable to parse currency symbol(£,€) from json to .csv file
下面是我的java代码
public Test parseTest(String test) {
Testresult = null;
try {
result = gson.fromJson(test, Test.class);
if (CAT.isDebugEnabled()) {
CAT.debug(result);
}
} catch (JsonSyntaxException e) {
CAT.warn(e.getMessage() + "\nCan't parse\n" + test);
}
return result;
}
解析Json我用的是下面的jar
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2</version>
</dependency>
下面是我的JSON:
Test": [
{
"A": "X;DOS533",
"B": "FCA BANK SPAEUR1.5BN21MAR2019",
"C": null,
"D": "AA BB EUR1.5BN",
"E": "€1.5BN Test LN BNK €100M 12M",
"Ccy": "EUR",
"TypeCode": "TML "
}
下面是在 unix 框中生成的 .csv 文件中的行。
4243842|Test:ABC|Active||6||FFTIAIT||Internal|X;DOS5KT|FCA BANK SPAEUR1.5BN21MAR2019|?1.5BN Test LN NWM ?100M 12M|TML|
此处 € 符号替换为 ?(问号)。
我在将英镑 (£) 从 .csv 文件转换为 .bcp 文件时遇到同样的问题。
我尝试传递字节流而不是字符串,它起作用了。
下面是更新后的代码
public Test parseTest(String test) {
Testresult = null;
try {
result = gson.fromJson(new InputStreamReader(new ByteArrayInputStream(test.getBytes("UTF-8"))), Test.class);
if (CAT.isDebugEnabled()) {
CAT.debug(result);
}
} catch (JsonSyntaxException e) {
CAT.warn(e.getMessage() + "\nCan't parse\n" + test);
}catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return result;
}
下面是我的java代码
public Test parseTest(String test) {
Testresult = null;
try {
result = gson.fromJson(test, Test.class);
if (CAT.isDebugEnabled()) {
CAT.debug(result);
}
} catch (JsonSyntaxException e) {
CAT.warn(e.getMessage() + "\nCan't parse\n" + test);
}
return result;
}
解析Json我用的是下面的jar
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2</version>
</dependency>
下面是我的JSON:
Test": [
{
"A": "X;DOS533",
"B": "FCA BANK SPAEUR1.5BN21MAR2019",
"C": null,
"D": "AA BB EUR1.5BN",
"E": "€1.5BN Test LN BNK €100M 12M",
"Ccy": "EUR",
"TypeCode": "TML "
}
下面是在 unix 框中生成的 .csv 文件中的行。
4243842|Test:ABC|Active||6||FFTIAIT||Internal|X;DOS5KT|FCA BANK SPAEUR1.5BN21MAR2019|?1.5BN Test LN NWM ?100M 12M|TML|
此处 € 符号替换为 ?(问号)。
我在将英镑 (£) 从 .csv 文件转换为 .bcp 文件时遇到同样的问题。
我尝试传递字节流而不是字符串,它起作用了。
下面是更新后的代码
public Test parseTest(String test) {
Testresult = null;
try {
result = gson.fromJson(new InputStreamReader(new ByteArrayInputStream(test.getBytes("UTF-8"))), Test.class);
if (CAT.isDebugEnabled()) {
CAT.debug(result);
}
} catch (JsonSyntaxException e) {
CAT.warn(e.getMessage() + "\nCan't parse\n" + test);
}catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return result;
}