我有一个应用程序,它有一个脚本,可以读取 json 内容的文件。脚本是:
NSString *jsonString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
NSLog(@"%@", jsonString);
//filepath debug log: /var/mobile/Applications/1394B0D1-5B12-445D-BDFA-7B1E2661B685/Documents/json_branch_1_ru
在 iPhone 模拟器中一切正常,返回文本是正确的:
{"id":1,"add":"Казахстан, Алматы, улица Толе би, 73а","lon":"43.254677","lat":"76.934434","bnkid":42,"al":" ","rat":10,"prod":"","valid":1,"wrktime":"с физ.лицами: понедельник-пятница: 09:00-18:00 с юр.лицами: Нет данных" }
当我在我的设备上测试应用程序时,返回的文本编码不正确:
{"id":1,"add":"–ö–∞–∑–∞—Ö—Å—Ç–∞–Ω, –ê–ª–º–∞—Ç—ã, —É–ª–∏ —Ü–∞ –¢–æ–ª–µ –±–∏, 73–∞","lon":"43.254677","lat":"76.934434","bnkid":42,"al":"" ,"rat":10,"prod":"","valid":1,"wrktime":"—Å —Ñ–∏–∑。–ª–∏—Ü–∞–º–∏: –ø– æ–Ω–µ–¥–µ–ª—å–Ω–∏–∫-–ø—è—Ç–Ω–∏—Ü–∞:09:00-18:00 —Å —é—Ä。 ª–∏—Ü–∞–º–∏: –ù–µ—Ç –¥–∞–Ω–Ω—ã—Ö"},{"id":2,"add":"–ö–∞– ∑–∞—Ö—Å—Ç–∞–Ω, –ê–ª–º–∞—Ç—ã, –º–∫—Ä. 5, 30","lon":"43.231442","lat" :"76.867923","bnkid":42,"al":"","rat":10,"prod":"","valid":1,"wrktime":"09:00 - 18:00" }
问题是什么?
注意:
1.我的文件没有扩展名
2.用utf-8编码保存的文件