天软金融分析.NET函数大全 > TSL函数 > 基础函数 > 字符串 > 多语言支持函数

ExportJsonStringUTF8    

简述
将天软数组转换为UTF8编码的Json串,解决与第三方交互时的转码问题。
定义
ExportJSONStringUTF8(data:anytype[,N:Integer]): String;
参数
名称类型说明
Data天软数据,任意数据类型。
Ninteger可选参数,要保留的小数位数。为0时保留1位小数,大于16或小于0时保留全部小数位数
返回值String字符串,UTF8编码的Json字符串。
  • 范例

    范例01:
    a:=select ['StockID'],['StockName'],datetostr(['date']) as 'date',['close']
      from markettable datekey 20200901T
      to 20200902T of 'SZ000002' end;
    return ExportJSONStringUTF8(a);

    //返回字符串
    [{"StockID":"SZ000002","StockName":"涓 绉戯肌","date":"2020-09-01","close":27.22},{"StockID":"SZ000002","StockName":"涓 绉戯肌","date":"2020-09-02","close":27.52}]

    范例02:与python交互中的应用
    pythonCode
    import sys
    sys.path.append('C:\Program Files\Tinysoft\Analyse.NET')
    import TSLPy3
    s="""
    a:=select ['StockID'],['StockName'],datetostr(['date']) as 'date',['close']
      from markettable datekey 20200901T
      to 20200902T of 'SZ000002' end;
      return ExportJSONStringUTF8(a);
    """
    data = TSLPy3.RemoteExecute(s,{})
    print(data[1].decode('utf8'))

    //python中返回:
    [{"StockID":"SZ000002","StockName":"万 科A","date":"2020-09-01","close":27.22},{"StockID":"SZ000002","StockName":"万 科A","date":"2020-09-02","close":27.52}]

    范例03:将数组转化为json串,并保留2位小数
    s:=array((1.3245,2.5123),('Tinysoft天软','天软科技'));
    return ExportJSONStringUTF8(s,2);

    //返回字符串:"[[1.32,2.51],[\"Tinysoft澶╄蒋\",\"澶╄蒋绉戞妧\"]]"
相关