ForeverZer0 / SharpNBT

A pure CLS-compliant C# implementation of the Named Binary Tag (NBT) format specification commonly used with Minecraft applications, allowing easy reading/writing streams and serialization to other formats.
MIT License
25 stars 9 forks source link

I want to restore Nbt string how to do? #10

Closed NingLiu1998 closed 11 months ago

NingLiu1998 commented 1 year ago

This is the data I receive

image

如果我直接序列化json,NBT 格式和原来的就不对了

If I serialize json directly, the NBT format is wrong with the original one

JsonConvert.SerializeObject(tag);

image

SharpNBT.SNBT.StringNbt.Parse 之后如何转回原来的?

How do I switch back to the original after SharpNBT.SNBT.StringNbt.Parse?

ForeverZer0 commented 1 year ago

I am uncertain what is the expected/actual values you are getting, but I will note that SNBT is not JSON, though raw strings of JSON text can be used as a string value, which is common. This string can then be converted by the application into the expected type, but the SNBT itself is not JSON, nor is it likely to process it correctly.

SNBT would be something more akin to this:

{jsonText: "{\"command\": {\"name\": \"quit\"}}" }

Note that the actual JSON is passed as a string, not in JSON form, and the similarity between SNBT and JSON can be deceptive. I am unsure if you are receiving raw JSON that shouldn't be parsed as SNBT, or if you are attempting to process the SNBT key/value as JSON, when you should only be processing the text value.

NingLiu1998 commented 1 year ago

You are right, I found my train of thought a little bit wrong, thank you!