' NSInvalidArgumentException',原因:' JSON写入中的无效类型(__NSDate)'

时间:2016-09-23 02:41:29

标签: json swift parsing parse-platform

我正在使用Parse Server,我无法弄清楚为什么这只会在Parse Live Query中发生。

有什么想法吗?它正在工作,然后随机停止工作。

以下是:

2016-09-22 22:36:37.484 inSparkle[34009:476038] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (inSparkle.WeekList)'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010749834b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x0000000106ef921e objc_exception_throw + 48
    2   CoreFoundation                      0x0000000107501265 +[NSException raise:format:] + 197
    3   Foundation                          0x0000000103745284 _writeJSONValue + 668
    4   Foundation                          0x000000010379aaa2 ___writeJSONObject_block_invoke + 226
    5   CoreFoundation                      0x000000010741f76c __NSDictionaryEnumerate + 828
    6   Foundation                          0x000000010379a896 _writeJSONObject + 430
    7   Foundation                          0x000000010374516d _writeJSONValue + 389
    8   Foundation                          0x000000010379aaa2 ___writeJSONObject_block_invoke + 226
    9   CoreFoundation                      0x000000010741f76c __NSDictionaryEnumerate + 828
    10  Foundation                          0x000000010379a896 _writeJSONObject + 430
    11  Foundation                          0x000000010374516d _writeJSONValue + 389
    12  Foundation                          0x000000010379aaa2 ___writeJSONObject_block_invoke + 226
    13  CoreFoundation                      0x000000010741f76c __NSDictionaryEnumerate + 828
    14  Foundation                          0x000000010379a896 _writeJSONObject + 430
    15  Foundation                          0x000000010374516d _writeJSONValue + 389
    16  Foundation                          0x0000000103744f94 -[_NSJSONWriter dataWithRootObject:options:error:] + 124
    17  Foundation                          0x0000000103744e74 +[NSJSONSerialization dataWithJSONObject:options:error:] + 333
    18  ParseLiveQuery                      0x00000001042755ec _TFFC14ParseLiveQuery6Client18sendOperationAsyncFOS_15ClientOperationGC10BoltsSwift4TaskT__U_FzT_T_ + 220
    19  ParseLiveQuery                      0x000000010427590a _TPA__TFFC14ParseLiveQuery6Client18sendOperationAsyncFOS_15ClientOperationGC10BoltsSwift4TaskT__U_FzT_T_ + 202
    20  ParseLiveQuery                      0x0000000104275988 _TPA__TTRXFo__dT_zoPs9ErrorType__XFo__iT_zoPS___ + 56
    21  ParseLiveQuery                      0x000000010427affe _TPA__TTRXFo__dT_zoPs9ErrorType__XFo__iT_zoPS___.18 + 14
    22  BoltsSwift                          0x0000000102a10de7 _TZFO10BoltsSwift9TaskState11fromClosurefFzT_xGS0_x_ + 55
    23  BoltsSwift                          0x0000000102a150f4 _TPA__TFFC10BoltsSwift4TaskcFTOS_8Executor7closureFzT_x_GS0_x_U_FT_T_ + 132
    24  libdispatch.dylib                   0x00000001099cd980 _dispatch_call_block_and_release + 12
    25  libdispatch.dylib                   0x00000001099f70cd _dispatch_client_callout + 8
    26  libdispatch.dylib                   0x00000001099d4e6b _dispatch_queue_serial_drain + 236
    27  libdispatch.dylib                   0x00000001099d5b9f _dispatch_queue_invoke + 1073
    28  libdispatch.dylib                   0x00000001099d607f _dispatch_queue_override_invoke + 683
    29  libdispatch.dylib                   0x00000001099d83b7 _dispatch_root_queue_drain + 720
    30  libdispatch.dylib                   0x00000001099d808b _dispatch_worker_thread3 + 123
    31  libsystem_pthread.dylib             0x0000000109da6746 _pthread_wqthread + 1299
    32  libsystem_pthread.dylib             0x0000000109da6221 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

这是我的WeekList子类:

    //
//  WeekList.swift
//  inSparkle
//
//  Created by Trever on 12/17/15.
//  Copyright © 2015 Sparkle Pools. All rights reserved.
//

import Foundation
import Parse

class WeekList: PFObject, PFSubclassing {

    class func parseClassName() -> String {
        return "ScheduleWeekList"
    }

    var apptsRemain : Int {
        get { return objectForKey("apptsRemain") as! Int }
        set { setObject(newValue, forKey: "apptsRemain") }
    }

    var isOpenWeek : Bool {
        get { return objectForKey("isOpenWeek") as! Bool }
        set { setObject(newValue, forKey: "isOpenWeek") }
    }

    var weekStart : NSDate {
        get { return objectForKey("weekStart") as! NSDate }
        set { setObject(newValue, forKey: "weekStart") }
    }

    var weekEnd : NSDate {
        get { return objectForKey("weekEnd") as! NSDate }
        set { setObject(newValue, forKey: "weekEnd") }
    }

    var maxAppts : Int {
        get { return objectForKey("maxAppts") as! Int }
        set { setObject(newValue, forKey: "maxAppts") }
    }

    var numApptsSch : Int {
        get { return objectForKey("numApptsSch") as! Int }
        set { setObject(newValue, forKey: "numApptsSch") }
    }

}

然后这里也是我制作和订阅的查询代码:

    func getNumPOCThisWeek() {
    let calendar = NSCalendar.currentCalendar()
    calendar.firstWeekday = 2
    calendar.timeZone = NSTimeZone(abbreviation: "UTC")!
    var startOfWeek : NSDate?
    calendar.rangeOfUnit(.WeekOfYear, startDate: &startOfWeek, interval: nil, forDate: NSDate())

    //        let weekObj : WeekList!
    let query = WeekList.query()!
    query.whereKey("weekStart", equalTo: startOfWeek!)
    do {
        let weekObj = try query.getFirstObject() as! WeekList
        print(weekObj)

        let weekNumber = ScheduleObject.query()!
        weekNumber.whereKey("weekObj", equalTo: weekObj)
        weekNumber.countObjectsInBackgroundWithBlock({ (counted : Int32, error : NSError?) in
            self.thisWeekPOCNumber.text = String(counted)
            weekNumber.subscribe()
                .handle(Event.Created) {_, item in
                    self.getNumPOCThisWeek()
                }
                .handle(Event.Updated) {_, item in
                    self.getNumPOCThisWeek()
                }
                .handle(Event.Deleted) {_, item in
                    self.getNumPOCThisWeek()
                }
                .handle(Event.Entered) {_, item in
                    self.getNumPOCThisWeek()
                }
                .handle(Event.Left) {_, item in
                    self.getNumPOCThisWeek()
            }
        })
    } catch {
        print(error)
    }
}

如果我注释掉实时查询,它根本不会有任何问题。我试图重新启动Parse Server,确保我的类正在加载,然后重新启动整个服务器,没有运气。我已经清除了我的构建文件夹,甚至在Xcode中派生了数据。有什么想法吗?

0 个答案:

没有答案