UE4 JSON read-write method

Source: Internet
Author: User

UE4 JSON read-write method


There are many open source libraries for JSON parsing. UE4 JSON is used in the public->serialization of the code.

Header file contains: Json.h

the Read and write creation of JSON is a single mode of static formation, with the Jsonwrite or Jsonreader factory to create.

Take the reading as an example:

Read the code:
float _score = Myplayerstate->getscore (); Fstring _player_name = Myplayerstate->getname (); int _kills = Myplayerstate->getkills (); int _deaths = Myplayerstate->getdeaths (); Fstring Jsonstr; tsharedref< Tjsonwriter<tchar, tcondensedjsonprintpolicy<tchar> > > jsonwriter = TJsonWriterFactory <tchar, tcondensedjsonprintpolicy<tchar> >::create (&JSONSTR); <span style= "White-space:pre" > </span>jsonwriter->writeobjectstart (); Jsonwriter->writevalue (TEXT ("name"), _player_name); Jsonwriter->writevalue (TEXT ("Score"), _score); Jsonwriter->writevalue (TEXT ("deaths"), _deaths); Jsonwriter->writevalue (TEXT ("Kills"), _kills) <span style= "White-space:pre" ></span>jsonwriter- >writeobjectend ();//Close The writer and finalize the output such that jsonstr have what we wantjsonwriter->close (); return jsonstr;



The Write object can be an array of objcet or arrays, value values.

A read and write process, start and end to correspond, because of the JSON format requirements, or how I know where an object or the end of an array. This can cause confusion.


All reads and writes are completed after close.

See the online example very few, oneself affixed a, oneself also convenient!


----------------------------

If you have any questions, please feel free to contact us!

Thank you so much!

UE4 JSON read-write method

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.