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

bool类型序列化错误 #9

Closed
cjhxajh opened this issue Aug 2, 2022 · 2 comments
Closed

bool类型序列化错误 #9

cjhxajh opened this issue Aug 2, 2022 · 2 comments

Comments

@cjhxajh
Copy link

cjhxajh commented Aug 2, 2022

public class Test
{
public bool boolVal = true;
public int intVal = 3;
}

Test t = new Test();
t.boolVal = false;
t.intVal = 99;
var json = CatJson.JsonParser.ToJson(t);
Debug.Log(json);
/* 输出
{
"intVal":99
}
/
var lt = CatJson.JsonParser.ParseJson(json);
Debug.Log(lt.boolVal+" " + lt.intVal);
/
输出
True 99
*/
上面boolVal值改成了false 反序列化时值是True

@cjhxajh
Copy link
Author

cjhxajh commented Aug 2, 2022

CatJson.JsonParser.IgnoreDefaultValue = false;
禁用忽略默认值 输出是对的

另外一个问题禁用默认值 string类型必需给一个非null的值能才序列化,不然会报错

@CatImmortal
Copy link
Owner

使用最新版本V2可以通过JsonCareDefaultValue禁用被标记类型的默认值忽略

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