Bwar / CJsonObject

Ultralightweight JSON parser in C++ based on cJSON
MIT License
648 stars 239 forks source link

even if you give an initial value to a float variable, json parsing gives you an initial value. Without the initial value, the result is a little bit like 4.6085e+33. #1

Closed kematy closed 5 years ago

kematy commented 5 years ago

In my case, even if you give an initial value to a float variable, json parsing gives you an initial value. Without the initial value, the result is a little bit like 4.6085e+33. jsontest.zip

kematy commented 5 years ago

This is not the case with integers.

kematy commented 5 years ago

In my operating system (win10), when I execute the EXE I generate, as long as the integer is incremented by a small enough number, it can be parsed by cjson。

kematy commented 5 years ago

I suspect this is a matter of the compiler handling floating-point precision

kematy commented 5 years ago

The compiler I use is mingw32 7.4.0。

Bwar commented 5 years ago

on trip, I will reply this weekend.

---Original--- From: "kematy"notifications@github.com Date: Tue, Jul 16, 2019 20:25 PM To: "Bwar/CJsonObject"CJsonObject@noreply.github.com; Cc: "Subscribed"subscribed@noreply.github.com; Subject: Re: [Bwar/CJsonObject] even if you give an initial value to a float variable, json parsing gives you an initial value. Without the initial value, the result is a little bit like 4.6085e+33. (#1)

The compiler I use is mingw32 7.4.0。

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

kematy commented 5 years ago

Waiting for your good news。祝你旅途愉快!

kematy commented 5 years ago

另外,这个cjsonobject 怎么识别null和true、false,这也是经常要用到的。好像没有这样的实例函数,只有一个IsEmpty()?

Bwar commented 5 years ago

问题不在.Get(0,fvalue),在cJSON.c里的print_double(),在你的例子中做了json赋值,赋值时ToString()方法会调用print_double(),而print_double()将.0截掉了,值变成了整数。 另外,你提到的null,我也加入了对null的支持,不过建议能不用null就尽量别用null,null虽然是json属于json标准,但用在C++这种强类型语言里不是太合适,明确一个json value是string、int、float或{}又或[]会更好。

kematy commented 5 years ago

非常感谢,试过了,已经比较完善了,感谢你的辛劳和付出。