delphi解析TFDJsonDataSets生成的TJsonObject对象时提示
存在于多字节代码页中的Unicode字符没有映射
一、问题的提出:
服务器端需要返回Json对象: function getTablesStruct :TJSonObject;
LFDJsonDatasets := TFDJsonDatasets.Create;
LFDJSONInterceptor:=TFDJSONInterceptor.Create;
Result:=TJSonObject.Create;
// 生成LFDJsonDatasets :
ProduceAbigTFDJSONDataSets(LFDJsonDatasets,
LDatasTab1Key,LDatasTab1Sql,
LDatasTab2Key,LDatasTab2Sql,
LDatasTab3Key,LDatasTab3Sql );
// 返回TJSonObject对象 :
ifFinished:=LFDJSONInterceptor.DataSetsToJSONObject(
LFDJsonDatasets,
Result );
现在如果:客户器端不用TDSRestConnection的delphi客户端连接来反序列化ATFDJSONDataSets:
TFDJSONInterceptor.JSONObjectToDataSets( ATJSONObject, ATFDJSONDataSets );
FDAdaptedDataSet := TFDJSONDataSetsReader.GetListValueByName(
ATFDJSONDataSets ,'取物品资料表');
而采用Rest办法:自然就需要解析服务器端返回的TJSonObject,而该Json对象中,包含类似这样的“乱码”:

Json解析出对值“乱码”:直接Base64解码后,UTF8编码还原时,会提示:
'No mapping for the Unicode character exists in the target multi-byte code page'.
即:存在于多字节代码页中的Unicode字符没有映射。
二、分析
1、这样的“乱码”是什么码,怎么来的
这样的“乱码”是“压缩流的二进制编码”的字符串,而压缩流的字符串是Base64对二进制格式适配数据集的内存流的编码的字符串,编码过程的源代码的流程如下:
--->从TFDJSONDataSets中获取需要返回客户端的TJSONObject
class function TFDJSONInterceptor.DataSetsToJSONObject(
const ADataSets: TFDJSONDataSetsBase;
const AJSONObject: TJSONObject): Boolean;
Result := ItemListToJSONObject(ADataSets.FDataSets, AJSONObject);
--->TFDJSONDataSets从其TItemList列表获取各项适配数据集的值
class function TFDJSONInterceptor.ItemListToJSONObject(
const AList: TItemList; const AJSONObject: TJSONObject): Boolean;
var
LPair:

本文分析了Delphi环境下TFDJsonDataSets生成的TJsonObject对象在解析时出现乱码的原因,深入探讨了Base64编码、压缩流及二进制字符串的处理过程,并提供了解析乱码的详细步骤。
最低0.47元/天 解锁文章
947

被折叠的 条评论
为什么被折叠?



