Does NSJSONSerialization deserialize numbers as NSDecimalNumber?

后端 未结 4 2093
甜味超标
甜味超标 2021-02-08 03:37

Take the following piece of code:

NSError *error;
NSString *myJSONString = @\"{ \\\"foo\\\" : 0.1}\";
NSData *jsonData = [myJSONString dataUsingEncoding:NSUTF8St         


        
4条回答
  •  面向向阳花
    2021-02-08 04:15

    I had the same problem, except I'm using Swift 3. I made a patched version of the JSONSerialization class that parses all numbers as Decimal's. It can only parse/deserialize JSON, but does not have any serialization code. It's based on Apple's open source re-implementation of Foundation in Swift.

提交回复
热议问题