头文件包含:Json.h
Json的读写创建是static形成的单例模式,有JsonWrite或JsonReader的Factory来创建(Create)出来。
以读方式为例子:
读的代码: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 has what we want JsonWriter->Close(); return JsonStr;
写的对象可以为Objcet或Array数组,value值。
一个读写过程中,Start和End要对应,因为Json格式的要求,要不我怎么知道哪里是一个对象或数组的结尾呢。这样就会造成混乱的。
所有的读写都在close之后才真正的完成处理。
看网上例子很少,自己贴个,自己也方便!
----------------------------
若有问题,请随时联系!
非常感谢!
原文地址:http://blog.csdn.net/cartzhang/article/details/41009343