NSJSONSerialization.JSONObjectWithData
त्रुटि जब इस तरह की स्ट्रिंग का उपयोग कर" abc "लेकिन सफलता का उपयोग कर" 123 "NSJSONSerialization त्रुटि। कोड = 3840 "चरित्र के आसपास अवैध मान 0
मैं नहीं जानता कि क्यों।
त्रुटि लॉग
2015-11-04 17:42:02.997 SwiftJsonDemo[27196:2701028] Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}
कोड
//var str = "123" // ok
var str = "abc" // error
let strData = str.dataUsingEncoding(NSUTF8StringEncoding)
if let d = strData {
let urlStr = String(data: d, encoding: NSUTF8StringEncoding)
do {
let json = try NSJSONSerialization.JSONObjectWithData(d, options: NSJSONReadingOptions.AllowFragments)
} catch let e {
print(e)
}
} else {
print("data error")
}
बहुत बहुत धन्यवाद। समझ गया! – aotian16