Read error
C# For Unity
fbs
namespace Scripts.CSharpCode.FlatBuffers;
table GameKeyIconCfg {
assetName:string(key);
bundleName:string;
}
table GameTableIconCfg{
icon_cfg:[GameKeyIconCfg];
}
root_type GameTableIconCfg;
Json
{ "icon_cfg": [ { "assetName": "crossbow", "bundleName": "base_ui" }, { "assetName": "icon_0", "bundleName": "base_ui" }, { "assetName": "background_1", "bundleName": "background_1" }, { "assetName": "background_2", "bundleName": "background_2" }, { "assetName": "background_3", "bundleName": "background_3" }, { "assetName": "background_4", "bundleName": "background_4" } ] }
var _gameTableIconCfg = GameTableIconCfg.GetRootAsGameTableIconCfg(buffer); var iconCfgLength = _gameTableIconCfg.IconCfgLength; var t1 = _gameTableIconCfg.IconCfg(0)?.AssetName; var t2 = _gameTableIconCfg.IconCfgByKey("crossbow")?.AssetName;
iconCfgLength== 6 t1="crossbow" t2=null
ByKey only works if the vector has been sorted, it will likely not find elements if it hasn't been sorted.
Is my use wrong?
That looks to be the same problem as https://github.com/google/flatbuffers/issues/5424 where flatc doesn't sort the JSON. It works if instead you construct the data in code, since that will have a CreateSortedVectorOfGameKeyIconCfg function.
Request to add JSON sort to flatc. I have too many jsons. I don't know C++.
Working on it..
Ok, this should implement JSON sort: https://github.com/google/flatbuffers/commit/32f47ad24727c7af17996aed5e48840e9139b2f5
Let me know if it works for you.
This issue is stale because it has been open 6 months with no activity. Please comment or this will be closed in 14 days.