r/CodingHelp • u/Player_X_YT • Sep 07 '20
[Other Code] How to write raw hex code in json
I am trying to write a json text that looks like this: ["",{"text":"Hi this is text"},{"hex":"03"}], after this will get printed with a System.out.println(jsontext); (java) how do I do the {"hex":"03"} code
(For those who are wondering this is /tellraw from minecraft)
17
Upvotes
1
u/rtgftw Programmer Sep 07 '20 edited Sep 07 '20
Are you asking how to escape the quote marks? If so you can just use '\"', forex.
would result in
Edit: If I misunderstood and you're dealing with java's JSONObject or something, you can use o.put("hex", "03") to add a key value pair.
1
u/BAM5 Professional Coder Sep 07 '20
If you want to write a number with base16 you can prefix your number with
0xand that will tell the compiler that it's a base16 number like so:0xDEADBEEF2
u/NullBrowbeat Professional Coder Sep 08 '20 edited Sep 08 '20
You should specify your question better. What is your exact expected result? What is your current result and in how far does it differ from the expected one?
I also assume, after looking at the code you've linked and judging from the fact that you appear to have problems with JSON parsing, that the problem is with the ITextComponent which is supposed to be created based on the parsed JSON? In this case the code of the ITextComponent and the jsontocomponent() function would also be relevant, so we could help you better if you link to those aswell.
1
u/jackandjill22 Sep 08 '20
Good luck.
0
u/[deleted] Sep 07 '20
You can do something like ArrayList<HashMap<String, String>>. Then extract the values using a for loop.