nested key-value pairs in form-urlencoded post request play WS

时间:2015-05-12 23:06:42

标签: json scala post playframework

I need to construct a data map of type public TreeNode createDocuments() { TreeNode rootNode = new DefaultTreeNode(new Document(), null); List<Document> documentRootNodeList = dao.getDocumentsRoot(); for (Document doc : documentRootNodeList) { TreeNode node = new DefaultTreeNode(doc, rootNode); createSubNode(doc, node); } return rootNode; } public void createSubNode(Document doc, TreeNode node) { List<Document> documentList = dao.getDocumentsNode(doc); for (Document subDoc : documentList) { TreeNode subNode = new DefaultTreeNode(subDoc, node); createSubNode(subDoc, subNode); } } for a Map[String, Seq[String]] form-urlencoded request in Play WS library.

The API I'm using, requires to submit the following form fields: token and an array of key-value pairs called POST.

So, essentially, I need to convert a JSON like:

userPreferences

Into map of type { token: 12345, userPreferences[0]: { key1: value1, key2: value2 }, userPreferences[1]: { key2: value2 } } . What's the protocol? Will such approach work?

[String, Seq[String]]

How should I encode a nested JSON object as a key-value string? Do I just add pairs into the sequence converting to strings if necessary? How would the final query string look like?

I'm not using the whole Play framework, only this library for HTTP requests.

Might be a duplicate, but I've searched for almost an hour and haven't found an example.

0 个答案:

没有答案