I am attempting to recreate the below JSON in JAVA.
[{
"Operation": {
Product: "MyProduct",
Noun: "MyNoun",
Verb: "MyVerb"
},
"Authentication": {
UserID: "UserName",
Password: "Password"
}}]
I feel like the Maps
are the way to go. But I am having trouble forming the proper structure.
Map<String,String> opsDictionary = new HashMap<String,String>();
opsDictionary.put("Product","MyProduct");
opsDictionary.put("Noun","MyNoun");
opsDictionary.put("Verb", "MyVerb");
Map<String,String> authDictionary = new HashMap<String,String>();
authDictionary.put("UserID","UserName");
authDictionary.put("Password", "Password");
JSONObject postdata = new JSONObject();
postdata.put("Operation", opsDictionary);
postdata.put("Authentication", authDictionary);
Which spits out this INCORRECT version:
{
"Authentication": "{UserID=CADEMO, Password=TESTPASSORD}",
"Operation": "{Noun=User, Product=TOPSInventory, Verb=Authenticate}"
}
I toyed with the idea of packaging up the Maps in a bundle
Bundle dataBundle = new Bundle();
dataBundle.putStringArray("Operation", opsDictionary);
dataBundle.putStringArray("Authentication", authDictionary);
What am I doing wrong?
I was able to replicate this format in my iOS version using Dictionaries.
NSMutableDictionary * dicOperation = [[NSMutableDictionary alloc]init];
[dicOperation setValue:product forKey:@"Product"];
[dicOperation setValue:noun forKey:@"Noun"];
[dicOperation setValue:verb forKey:@"Verb"];
NSMutableDictionary * dicAuthentication = [[NSMutableDictionary alloc] init];
[dicAuthentication setValue:username forKey:@"UserID"];
[dicAuthentication setValue:password forKey:@"Password"];
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dictPackage options:NSJSONWritingPrettyPrinted error:&error];
I was hoping there was a similar solution for Android.