2

我有这个创建 json 文件的宏,
但即使我指定encoding='utf-8' bom了,我也没有得到 utf-8 文件。

%macro json4datatables_useformat(ds,path,file,charvars,numvars)
    / 
    DES="json4datatables(ds,path,file,charvars,numvars)";

    /* creates a json with no headers
     * a bit like a csv without the first line
     * it takes thus less space
     * but you have to know which column is what
     */

    data _null_;
        length line $300;
        set &ds nobs=nobs end=end;
        file "&path.&file." encoding='utf-8' bom/**/ ;

        line = '[';

        %if &charvars ne %then %do;
            %do i=1 %to %sysfunc(countw(&charvars));
                %let charvar = %scan(&charvars, &i);
                %if &i ne 1 %then %do;
                    line = cats(line,',');
                %end;
                line = cats(line,'"',vvalue(&charvar),'"');
            %end;
        %end;
        %if &numvars ne %then %do;
            %do i=1 %to %sysfunc(countw(&numvars));
                %let numvar = %scan(&numvars, &i);
                line = catx(',',line,vvalue(&numvar));
            %end;
        %end;

        line = cats(line,']');

        if _n_=1 then put '{"data": [';
        if not end then put line +(-1) ',';
        else do;
            put line;
            put ']}';
        end;
        run;

%mend json4datatables_useformat;

我注意到,因为重音在我显示 json 文件的网页上显示为奇怪的字符。
只需以崇高的文本打开 json 文件并执行File>Save with Encoding>UTF-8即可解决问题。(不需要 BOM。)

还有另一种强制 utf-8 编码的方法吗?

编辑:我在 Windows 上使用 SAS EG 7.1 、 SAS 9.3 。

4

1 回答 1

0

您的浏览器没有合适的字符集和/或字体来呈现您的数据。

添加您要浏览的语言:

控制面板 -> 区域和语言 -> 键盘和语言 -> 显示语言 -> 安装/卸载语言

于 2017-01-12T21:40:02.857 回答