#new JSONObject(String); doesnt work
1 messages · Page 1 of 1 (latest)
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
@viral horizon what are you trying to accomplish exactly?
and what json library are you using, etc
Not sure which json library will take such parameter.
But a string is not a valid json form. It either be a string array or a string value with a key in an object.
thats not true
older json specs stipulated that
but json can be a string
A JSON text is a serialized value. Note that certain previous
specifications of JSON constrained a JSON text to be an object or an
array. Implementations that generate only objects or arrays where a
JSON text is called for will be interoperable in the sense that all
implementations will accept these as conforming JSON texts.
JSON-text = ws value ws
value = false / null / true / object / array / number / string
wow did not know that
<dependency>
<groupId>dev.mccue</groupId>
<artifactId>json</artifactId>
<version>0.2.3</version>
</dependency>
dependencies {
implementation("dev.mccue:json:0.2.3")
}
https://repo1.maven.org/maven2/dev/mccue/json/0.2.3/json-0.2.3.jar
I spent a few months making a json lib, so its all fresh in my head
@viral horizon if you want to use it, this is how you turn a string into Json
import dev.mccue.json.Json;
public class Main {
public static void main(String[] args) {
Json value = Json.of("Hello");
System.out.println(value);
}
}
and this is how you parse a string containing json
import dev.mccue.json.Json;
public class Main {
public static void main(String[] args) {
Json value = Json.readString("""
{
"message": "hello"
}
""");
System.out.println(value);
}
}
what this'll output?
Detected code, here are some useful tools:
Exception in thread"main"java.lang.UnsupportedClassVersionError : dev / mccue / json / Json has been compiled by a more recent version of the Java Runtime(class file version61.0), this version of the Java Runtime only recognizesclass file versions up to60.0at java.base / java.lang.ClassLoader.defineClass1(Native Method) at java.base / java.lang.ClassLoader.defineClass(ClassLoader.java : 1010) at java.base / java.security.SecureClassLoader.defineClass(SecureClassLoader.java : 150) at java.base / jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java : 855) at java.base / jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java : 753) at java.base / jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java : 676) at java.base / jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java : 634) at java.base / jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java : 182) at java.base / java.lang.ClassLoader.loadClass(ClassLoader.java : 519) at Main.main(Main.java : 30)
@viral horizon I feel like there is more to what you are trying to do than just turning a string into json
Can you share more of your task/code you have so far?
If you give me a url i can show you how to do it without jackson
but if that did the job for you thats all well
also - try using HttpClient instead of URLConnection