Files
DP/PSMARK代码块/读取json文件.jsx

29 lines
986 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 创建一个文件对象指向桌面上的子图层名称.json文件
var desktop = Folder.desktop;
var file = new File(desktop + "/名称数据.json");
// 打开文件以进行读取
if (file.open('r')) {
var content = file.read();
file.close();
// 从JSON格式的字符串中删除前后的方括号并根据逗号分割为数组
var 名称数组 = content.replace(/^\s*\[|\]\s*$/g, '').split(/"\s*,\s*"/);
// 循环遍历数组并逐个弹出名称
for (var i = 0; i < 名称数组.length; i++) {
// 从每个名称中删除前后的双引号
var 名称 = 名称数组[i].replace(/^"|"$/g, '');
// 弹出整个名称
// alert("完整名称: " + 名称);
// 使用正则表达式提取括号内的内容
var matches = 名称.match(/\(([^)]+)\)/);
var 图案名称=matches [1]
//alert("图案名称: " + 图案名称);
}
} else {
alert("无法打开文件!");
}