Use of JSON serialization in Unity failed

Source: Internet
Author: User

    • Problem
//Why JSON serialization is not a problemdictionary<string,int> dic =Newdictionary<string,int>(); DiC. ADD ("1",1); stringStrjson =LitJson.JsonMapper.ToJson (DIC);//that's a problem.dictionary<int,int> Dic2 =Newdictionary<int,int>(); Dic2. ADD (1,1); stringStrJson2 =LitJson.JsonMapper.ToJson (DIC2); Debug.Log (strJson2);
    • Workaround

JSON serialization does not support structs, such as the Vector3 type in unity is not supported, so we have to transform the following

  

1 // Vector3 is originally a float type, but JSON does not support float type, so use double type 2  Public class Vector3obj 3 {4      Double x; 5      Double y; 6      Double Z; 7 }

    • Considerations for using JSON
    1. -Non-numeric key value in JSON string without double quotes
    2. -There is a tab in JSON like \ T, which looks like a space, but because it does not pass, it needs to be removed
    3. -Editor with BOM header will also cause

Use of JSON serialization in Unity failed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.