Re: the problem of the Chinese code
Posted: Fri Jun 03, 2016 5:49 am
Hello.
Can you send us .mrt file with this wrong symbols in datasource ?
Can you send us .mrt file with this wrong symbols in datasource ?
Business Intelligence Tool from Stimulsoft. Software for dashboards and reports. Reporting tools for any platform.
https://forum.stimulsoft.com/
heqichao wrote:Hello, it is a problem about Chinese disorder code.
I use json dataSource and the data is this,
but the Chinese Disorder Code in the report.
it is my report .Thank you.
http://test.arp.cn/appendix/M00/00/1A/C ... IN_RPT.mdc
Code: Select all
public static StiReport getReport(String reportPath,String httpQueryUrl){
StiReport stiReport = null;
try {
stiReport = StiSerializeManager.deserializeReport(new File(reportPath));
stiReport.getDictionary().getDataSources().clear();
stiReport.getDictionary().getDatabases().clear();
stiReport.getDictionary().getRelations().clear();
StiJsonDatabase db = null;
if(stiReport.getDictionary().getDatabases().get("JSON")== null){
db = new StiJsonDatabase("JSON",httpQueryUrl);
stiReport.getDictionary().getDatabases().add(db);
}else{
db=(StiJsonDatabase) stiReport.getDictionary().getDatabases().get("JSON");
}
JSONObject resuleObj =db.getJSONObject();
//TODO
JSONObject obj =resuleObj.getJSONObject("obj");
for(String ojbKey : obj.getNames(obj)){
JSONArray list =(JSONArray) obj.get(ojbKey);
StiDataTableSource ts = new StiDataTableSource("JSON"+"."+ojbKey, ojbKey, ojbKey);
ts.setColumns(new StiDataColumnsCollection());
Map keyMap =ReportUtil.getJsonArrayKey(list, new HashMap());
for(Object key :keyMap.keySet()){
ts.getColumns().add(new StiDataColumn((String)key, (String)key, StiSystemTypeEnum.SystemString.getSystemType()));
}
ts.setDictionary(stiReport.getDictionary());
stiReport.getDictionary().getDataSources().add(ts);
}
} catch (Exception e) {
e.printStackTrace();
}
stiReport.Render(false);
return stiReport;
}
public static Map getJsonArrayKey(Object obj,Map keyMap){
if(obj instanceof JSONArray){
JSONArray jsonArray =(JSONArray) obj;
int length = jsonArray.length();
for(int i=0;i<length;i++){
try {
JSONObject jsonObject =jsonArray.getJSONObject(i);
String[] names=JSONObject.getNames(jsonObject);
for(String name :names){
keyMap.put(name, name);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
else if(obj instanceof JSONObject){
JSONObject jsonObject =(JSONObject) obj;
String[] keys=JSONObject.getNames(jsonObject);
for(String key : keys){
try {
if(jsonObject.get(key) instanceof JSONArray){
getJsonArrayKey(jsonObject.get(key), keyMap);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return keyMap;
}