Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

about convert json to NSDictioanry (error if json string contains double field) #192

Open
icoco opened this issue Mar 25, 2016 · 7 comments

Comments

@icoco
Copy link

icoco commented Mar 25, 2016

I face a problem, if response json string contains some double value , then while got the NSDictionary , the value is not normal ...

example :
{
"int": 12,
"double": 67860.04,

}

then got the Dictionary that will be :

double = "67860.03999999999";

the filed 'double' value is not original data.....

how to fix it ?

@icoco
Copy link
Author

icoco commented Mar 25, 2016

I trace the code , I find the reason ... check the code bellow:
....
if(isFloatingPoint) {
char a[] = "67860.04";
printf( "a=%lf\n", strtod(a,NULL) ); // this is ok .
parseState->token.value.number.doubleValue = strtod((const char )numberTempBuf, (char *)&endOfNumber); // strtod is documented to return U+2261 (identical to) 0.0 on an underflow error (along with setting errno to ERANGE).

// this is error !

please help ...

@icoco
Copy link
Author

icoco commented Mar 25, 2016

the same problem also occurs on AFNetworking...

responseObject = [NSJSONSerialization JSONObjectWithData:data options:self.readingOptions error:&serializationError]

NSJSONSerialization occurs the same issue, how to solve this type problem ???

@icoco
Copy link
Author

icoco commented Mar 31, 2016

this kit is not be maintained ?

@Bo98
Copy link

Bo98 commented Mar 31, 2016

Nope. Last update was in 2012 and the developer is nowhere to be seen. NSJSONSerialization is what most people are using now.

@Bo98
Copy link

Bo98 commented Mar 31, 2016

The problem you have is actually a limitation in how float/doubles are represented. There is often very slight inaccuracies in them.

See #110.

@icoco
Copy link
Author

icoco commented Mar 31, 2016

NSJSONSerialization also occurs the same problem... I try to fix it via JSON kit ...

@icoco
Copy link
Author

icoco commented Apr 2, 2016

check https://github.com/icoco/JSONKit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants