[]小游戏项目 加载有中文的json文件 报错
我的json文件内容
{"Sheet1":[{"id":"0","name":"张三"},{"id":"1","name":"李四"},{"id":"2","name":"王麻子"},{"id":"3","name":"layabox"}]}
代码
public function LayaUISample() {
//初始化微信小游戏
MiniAdpter.init();
//初始化引擎
Laya.init(600, 400);
var url:String = "res/json/Sheet1.json";
Laya.loader.load(url, Handler.create(null, onJsonLoaded,[url]), null, Loader.JSON);
}
private static function onJsonLoaded(url:String,data:Object):void
{
var arr:Array = data.Sheet1;
Laya.loader.clearRes(url);
}
微信开发者工具中报错
Unexpected token in JSON at position 34;at api readFile success callback function
SyntaxError: Unexpected token in JSON at position 34
{"Sheet1":[{"id":"0","name":"张三"},{"id":"1","name":"李四"},{"id":"2","name":"王麻子"},{"id":"3","name":"layabox"}]}
代码
public function LayaUISample() {
//初始化微信小游戏
MiniAdpter.init();
//初始化引擎
Laya.init(600, 400);
var url:String = "res/json/Sheet1.json";
Laya.loader.load(url, Handler.create(null, onJsonLoaded,[url]), null, Loader.JSON);
}
private static function onJsonLoaded(url:String,data:Object):void
{
var arr:Array = data.Sheet1;
Laya.loader.clearRes(url);
}
微信开发者工具中报错
Unexpected token in JSON at position 34;at api readFile success callback function
SyntaxError: Unexpected token in JSON at position 34
没有找到相关结果
已邀请:
要回复问题请先登录
4 个回复
熊猫大侠
赞同来自: Aar0n
{"Sheet1":[{"id":"0","name":"\u5f20\u4e09"},{"id":"1","name":"\u674e\u56db"},{"id":"2","name":"\u738b\u9ebb\u5b50"},{"id":"3","name":"layabox"}]}
layabox
赞同来自: 熊猫大侠
开发者识别文件编码的方法示例(AS3版):
熊猫大侠
赞同来自:
linchenrr
赞同来自:
完成之后获取到data
bytes = new Byte(data);
str = bytes.readUTFBytes(bytes.length);
loader.endLoad(JSON.parse(str));
完美绕过引擎编码限制