Closed NingLiu1998 closed 10 months ago
CompoundTag
转为下面的格式My purpose is to convert CompoundTag
to the following format
string testNbtStr = "{Count:64b,id:\"minecraft:experience_bottle\"}";
Stringify ?but ...
It might work?
I do not completely understand what your problem is or how to help exactly. Is it the capital B
instead of a lowercase b
causing a problem? Any NBT implementation that follows the spec should accept both formats. There currently isn't an option in the library to specify one over the other, I believe it just uses the capitalized variant by default.
One minor thing to note (unrelated) is that, by convention, this is not a typical use of the byte tag, which is normally reserved for booleans and buffers, not just as integers to represent a count. It will of course still work, but the normal convention for the format is to use a VarInt for field that represents a count. It will result in one extra byte, but the intent will be clearer.
@ForeverZer0 我现在想把这个SNB字符串转为一个规范的Json字符串给 网页前端展示使用,然后统一能把Json字符串转回 NBT 字符串,我该怎么做
Now I want to convert this SNB string into a canonical Json string for display on the front end of the webpage, and then I can convert the Json string back into an NBT string. How should I do it?
As mentioned in #10, JSON and SNBT are similar, but not the same. If you are serializing to your own type, you will need to implement the logic for encoding it to JSON on that type. Minecraft opting to use stringified-NBT as string values inside JSON tags just makes this more confusing.
There is times when you will receive a string, which is JSON encoded, but within that JSON, it has a string value, which represents NBT, and is not JSON. This makes it so one has to pay strict attention to what the expected format is and how to deccode it properly, as the two formats are not interchangeable.
CompoundTag How can to StringNbt ?