Unity Game Framework uses - Json to convert objects to null

1. Problem description

    在使用UGF框架时,涉及将txt配置文件通过Utility.Json创建对象,结果没有报错,但是对象中的字段全部为null。
    项目使用的json辅助器是框架默认的,其是封装了unity提供的JsonUtility库。

2. Problem analysis

  1. Configuration file txt encoding problem
    I have read UGF documents written by some bloggers, and I have also encountered this problem. One of them is because the default encoding of TXT files saved through Excel is ANSI, so this is likely to occur when encountering configuration files with Chinese characters. question.
    Just reopen the TXT file and set the encoding to utf-8 when saving as.
  2. JsonUtility library support problem
    Through the second paragraph of the problem description, we can know that the default Json parsing of the framework uses the JsonUtility library, and the unity document describes it like this:
    insert image description here
    In the class I created, all fields are defined as attributes:
    pụblic string Host {get; set; }
    ``
    这应该就是问题所在,当我把get和set去掉后就成功OK了!
    

Guess you like

Origin blog.csdn.net/l1179237106/article/details/130878014