你好,
即使我做了研究,在我的情况下,我找不到任何可以帮助我的人.
所以,我尝试解析在xcode上由php脚本创建的Json,但是我有一个阻止进程的错误.
我是新人,所以我努力为我的问题布局做最好的...
我的错误:
[376:70b] Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Garbage at end.) UserInfo=0x8bc0f70 {NSDebugDescription=Garbage at end.
Run Code Online (Sandbox Code Playgroud)
我的代码:
NSData *jsonSource = [NSData dataWithContentsOfURL:
[NSURL URLWithString:@"http://codlobbyz.com/app/service.php"]];
NSError *err;
id jsonObjects = [NSJSONSerialization JSONObjectWithData:
jsonSource options:NSJSONReadingMutableContainers error:&err];
NSLog(@"%@", err);
Run Code Online (Sandbox Code Playgroud)
我的json:
[{"nom":"Call of duty ghost","date":"22 novembre","image":"appicon.png"},{"nom":"Fifa 14","date":"22 novembre","image":"appicon.png"}]
Run Code Online (Sandbox Code Playgroud)
我希望你能帮助我,谢谢你的答案.
我正在尝试TrainingSessionHistory在我的 SwiftUI 视图之一中对我的(核心数据对象)进行简单的获取请求,但得到了Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
struct TrainingHistoryView: View {
var trainingSession : TrainingSession
init(trainingSession : TrainingSession) {
self.trainingSession = trainingSession
let fetchRequest = FetchRequest(fetchRequest: TrainingSessionHistory.getBy(nb: 2, myTrainingSession: self.trainingSession))
print(fetchRequest.wrappedValue) // -> crash this EXC_BAD_INSTRUCTION
}
Run Code Online (Sandbox Code Playgroud)
TrainingSessionHistoryExtension : 创建获取请求
static func getBy(nb : Int, myTrainingSession : TrainingSession) -> NSFetchRequest<TrainingSessionHistory>{
let request:NSFetchRequest<TrainingSessionHistory> = TrainingSessionHistory.fetchRequest() as! NSFetchRequest<TrainingSessionHistory>
//request.predicate = NSPredicate(format: "trainingSession == %@", myTrainingSession)
request.fetchLimit = nb
let sortDescriptor = NSSortDescriptor(key: "date", ascending: true)
request.sortDescriptors = [sortDescriptor]
return …Run Code Online (Sandbox Code Playgroud)