Home > Back-end >  Java data assembly problem, how to assemble this array
Java data assembly problem, how to assemble this array

Time:11-28

 {" data ": {" type" : "posts," "attributes" : {" content ":" xiexie "}, "relationships" : {" discussion ": {" data" : {" type ":" discussions ", "id" : "99"}}}}} 


Not to say that the list can't specify the key, so can only use a map to the layers of Mosaic, but,,, this, this,,,






is that right? How a little not letter, I feel bad

CodePudding user response:


{
"Type" : "posts,"
"Attributes" : {
"Content" : "xiexie"
},
"Relationships" : {
"Discussion" : {
"Data" : {
"Type" : "discussions",
"Id" : "99"
}
}
}
},
{
"Type" : "posts,"
"Attributes" : {
"Content" : "xiexie"
},
"Relationships" : {
"Discussion" : {
"Data" : {
"Type" : "discussions",
"Id" : "99"
}
}
}
}
]

CodePudding user response:

Your New is a & lt; String, String> Types of map, you put a map that is certainly not ah,

CodePudding user response:

refer to the second floor pinoco response:
you New is a & lt; String, String> Types of map,


Bosses under the guidance of bai, then how will the whole

CodePudding user response:

Don't write generic or write generic map directly

CodePudding user response:

It's good

CodePudding user response:

Good good! Good good! Good good!

CodePudding user response:

reference 5 floor weixin_43795337 reply:
& lt; String, Object> Good



understand, thank you, but even so, also want to set at least two layer

CodePudding user response:

Your New is a & lt; String, String> Types of map, you put a map that is certainly not ah,

CodePudding user response:

The
refer to the original poster savage beast response:
 {" data ": {" type" : "posts," "attributes" : {" content ":" xiexie "}, "relationships" : {" discussion ": {" data" : {" type ":" discussions ", "id" : "99"}}}}} 


Not to say that the list can't specify the key, so can only use a map to the layers of Mosaic, but,,, this, this,,,






is that right? How a little not letter, I feel bad


Thought is right, implementation should be some problem., may be the final result of your transfer operator "" ";
Modify, according to others said to define the type of the map as Map Form, turns into a json string can be used to final reunification.
Refer to the following:
 
Public static void main (String [] args) {

Map Data=https://bbs.csdn.net/topics/new HashMap <> ();
Data. The put (" type ", "posts");

Map The attributes=new HashMap<> (a);
The attributes. The put (" content ", "xiexie");
Data. The put (" attributes ", the attributes).
Data. The put (" attributes2 ", net. Sf. Json. JSONObject. FromObject (attributes). The toString ());//this kind of situation in the final transformation, there will be a double quotes the escape of

Map DiscussionData=https://bbs.csdn.net/topics/new HashMap <> ();
DiscussionData. Put (" type ", "discussions");
DiscussionData. Put (" id ", "99");

Map The discussion=new HashMap<> (a);
The discussion. The put (" data ", discussionData);

Map Relationships=new HashMap<> (a);
Relationships. The put (" discussion ", the discussion);
Data. The put (" relationships ", relationships).

Map RootMap=new HashMap<> (a);
RootMap. Put (" data ", data);
System. The out. Println (.net. Sf. Json. The JSONObject. FromObject (rootMap). The toString ());
//print: {" data ": {" relationships" : {" discussion ": {" data" : {" id ":" 99 ", "type" : "discussions"}}}, "attributes" : {" content ":" xiexie} ", "type" : "posts", "attributes2" : "{" content \ ": " xiexie \ "} "}}
}


  • Related