fix case with nsdata in json

This commit is contained in:
Erik 2015-09-08 09:00:57 -04:00
parent 520a765c22
commit d8c8b4941e
2 changed files with 8 additions and 4 deletions

View File

@ -111,6 +111,8 @@ class SocketTestCases: NSObject {
static func testJSONWithBuffer(abstractSocketSend:SocketSendFunction) {
let testName = "testJSONWithBuffer"
let data = "0".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
func didGetResult(result:NSArray?, ack:AckEmitter?) {
if let json = result?.firstObject as? NSDictionary {
XCTAssertEqual((json.valueForKey("testString")! as! String), "test")
@ -123,7 +125,7 @@ class SocketTestCases: NSObject {
XCTFail("Should have NSDictionary as result")
}
}
let json = ["name": "test", "testArray": ["hallo"], "nestedTest": ["test": "test"], "number": 15]
let json = ["name": "test", "testArray": ["hallo"], "nestedTest": ["test": "test"], "number": 15, "buf": data]
abstractSocketSend(testName: testName, emitData: json, callback: didGetResult)
}

View File

@ -281,12 +281,14 @@ private extension SocketPacket {
}
return arr
} else if let dict = data as? NSMutableDictionary {
} else if let dict = data as? NSDictionary {
let mutDict = NSMutableDictionary(dictionary: dict)
for (key, value) in dict {
dict[key as! NSCopying] = shred(value, binary: &binary)
mutDict[key as! NSCopying] = shred(value, binary: &binary)
}
return dict
return mutDict
} else {
return data
}