javaa数组转化为json,将Json数组转换为Java数组
![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]:
还没有评论,来说两句吧...