javaa数组转化为json,将Json数组转换为Java数组

﹏ヽ暗。殇╰゛Y 2022-10-04 12:55 449阅读 0赞

![Image 1][]

I’m trying to convert this JSON string into an array:

{“result”:”success”,”source”:”chat”,”tag”:null,”success”:{“message”:”%message%”,”time”:%time%,”player”:”%player%”}}

I would like to output it like this:

%message%

I’m very new to java, I came from PHP where you could just do somthing along the lines of:

$result = json_decode($jsonfile, true);

echo “ “.$result[‘success’][‘message’];

Output: %message%

Is there an easy way to do this in java?

I searched for some similar topics but I didn’t really understand them. Could someone explain this to me like I’m 5?

解决方案

JSON-lib is a good library for JSON in Java.

String jsonString = “{message:’%message%’,player:’%player%’}“;

JSONObject obj = JSONObject.fromObject(jsonString);

System.out.println(“” + obj.get(“player”) );

[Image 1]:

发表评论

表情:
评论列表 (有 0 条评论,449人围观)

还没有评论,来说两句吧...

相关阅读