Home > front end >  Js format conversion
Js format conversion

Time:12-03

 {MSG=success operation, code=200, data=https://bbs.csdn.net/topics/[{noticeContent=junior middle school, elementary school winter vacation start time is on January 29, 2021 end time on February 21, 2021, please staff arranged before leaving work, all the teachers and students pay attention to the holiday travel safe! - always teach xuan, the serialVersionUID=1, noticeType=notice, noticeId=null, noticeTitle=winter holiday arrangement, the effective status=} in], type=NOTICE_INFO} 


Consult everybody, this how to convert a json object

CodePudding user response:

First string processing, the comma split into an array, then the array processing cycles

CodePudding user response:

You should always think to convert data into objects, the outer is an object, as for as the data is an array, you also can directly use traversal cycle

CodePudding user response:

I don't know can use the replace all=replace directly:

CodePudding user response:

This is not very simple? The=replace: as a json string parsing,


The import com. Google. Gson. JsonObject;
The import com. Google. Gson. JsonParser;

Public class String2Json {

Public String2Json () {
//TODO automatically generated constructor stub
}

Public static void main (String [] args) {
String jString="{MSG=success operation, code=200, data=https://bbs.csdn.net/topics/[{noticeContent=junior middle school, elementary school winter vacation start time is on January 29, 2021 end time on February 21, 2021, please staff arranged before leaving work, all the teachers and students pay attention to the holiday travel safe! - always teach xuan, the serialVersionUID=1, noticeType=notice, noticeId=null, noticeTitle=winter holiday arrangement, the effective status=} in], type=NOTICE_INFO}". The replace (
"=",
":");
JsonObject JsonObject=JsonParser. ParseString (jString) getAsJsonObject ();
System. The out. Println (jsonObject. ToString ());
}

}


The output

{" MSG ":" successful ", "code" : 200, the "data" : [{" noticeContent ":" the junior middle school, elementary school winter vacation start time is on January 29, 2021 end time on February 21, 2021, please staff arranged before leaving work, all the teachers and students pay attention to the holiday travel safe! - always teach xuan ", "serialVersionUID" : 1, "noticeType" : "notice", "noticeId", null, "noticeTitle" : "winter holiday arrangements", "status" : "in effect"}], "type" : "NOTICE_INFO"}

  • Related