NSDictionary *dic= [NSJSONSerialization JSONObjectWithData:[result dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&error];时失败,报:
Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (No string key for value in object around character 1.) UserInfo=0x8a31980 {NSDebugDescription=No string key for value in object around character 1.}
原来是result中的json格式错误引起的,以前一直没在意过,result 格式中使用的是单引号,所以造成无法解析。{'name':'lisi'} 就像这样,是无法解析的,将单引号换成双引号就可以正常解析了。{\"name\":\"lisi\"}