Jump to content

Json


RealNight

Recommended Posts

I have items.json file where are storing data about different itemstack (name, metadata, amount, enchants and nbt)

 

All works nice, but nbt format is not correct:

example: items.json

"name": "groupofitems",
	"items": [{
		"item": "IC2:itemToolChainsaw",
		"metadata": 27,
		"amount": 1,
		"enchantments": {},
		"nbt": {
			"charge": 30000.0d
		}
	}]
//next groups and items....

and result is - {"charge":"30000.0d",} - this is wrong and not working, it have to be {charge:30000.0d}

 

How to solve this problem?

Edited by RealNight
Link to comment
Share on other sites

11 minutes ago, diesieben07 said:

And how do you serialize the JSON again? You must have an NBTSerializer then, too, right?

No,

new NBTDeserializer()

is the name of the class file where it adapts minecraft NBTBase file (it is option for gson building like a string)

example: nbt:{"charge":"30000.0d"} (that is without adapting) , with adapting - nbt: {"charge":"30000.0d",} (comma is added in the end)

 

After that i apply settings that i made for gson for taking data from file.json and place data in the ItemConfig class

 

Edited by RealNight
Link to comment
Share on other sites

On 16.11.2017 at 1:06 AM, diesieben07 said:

No. NBTDeserializer is a json deserializer. It takes in JSON and produces an NBTBase instance. 

 

maybe you meant NBTDeserializer that implements json deserializer<ObjectName> (in our case NBTBase). In this class it turn to string everything that is found under nbt:{ }

Edited by RealNight
Link to comment
Share on other sites

1 minute ago, diesieben07 said:

Everything you are talking about until now is about taking JSON and turning it into java objects (NBTBase).

But your issue (as I understand it, please correct me if I am wrong) lies with the opposite direction, going from the Java objects (NBTBase, etc.) to JSON.

Sorry, however i am really stupid...

return (json != null) ? JsonToNBT.func_150315_a(json.toString().replaceAll("\"", "")) : null; and it works, wasted so many time   :S and yours...

 

 

Link to comment
Share on other sites

12 minutes ago, diesieben07 said:

What? Please, for once, clarify what you are actually talking about.

You keep saying things get replaced. Where exactly? When?

if we do in json file - charge: 30000.0d instead of "charge": "30000.0d" it means that we are trying to ask json library to generate invalid json. In gson part corrects this mistake and add quotes.

 

About a replaceall func: that is not the final version, i know that string can contain tree of nbt, so i need to check and figure all of them. Now, for 1 lvl tree of nbt it is more than enough.

Edited by RealNight
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.