Reputation: 990
public class Test {
public static void main(String[] args) throws ClientProtocolException, IOException {
HttpClient client = new DefaultHttpClient();
JSONObject json = new JSONObject();
json.put('set_boot' : True);
json.put('synchronous': True),
json.put('filters',filterList);
List filterList = new ArrayList();
filterList.put(6005076802818994A0000000000009DD);
json.put('volumes':volumeList);
List volumeList = new ArrayList();
volumeList.add('*all');
json.add( 'allow_unsupported': True);
StringEntity se = new StringEntity( json.toString());
System.out.println(se);
}
}
I am trying to add values to convert into a JSON query like:
{
'set_boot': True,
'synchronous': True,
'filters': {
'host_refs': [u '6005076802818994A0000000000009DD']
},
'volumes': ['*all'],
'allow_unsupported': True
}
But Eclipse is giving me error Invalid Character constant on line
json.put('set_boot' : True);
I have tried writing a few other words also like
json.put('set' : True);
But it still gives me the same error.
Upvotes: 0
Views: 1077
Reputation: 1502216
If this is meant to be Java, you want:
json.put("set_boot", true);
json.put("synchronous", true);
(There are similar problems later on.)
Note:
true
, not True
. You could use "True"
to set a string value if you wantfilterList
before it's declaredput
on a List
, when that method doesn't exist... you meant add
6005076802818994A0000000000009DD
is invalid. Did you mean to use a string literal?These are all just matters of the Java language, and have nothing to do with JSON in themselves.
Upvotes: 3
Reputation: 3727
Besides your snytax errors in Java, your JSON example is invalid syntax as well. Check it using jsonlint or other services. It should look like the following:
{
"set_boot": true,
"synchronous": true,
"filters": {
"host_refs": [
"6005076802818994A0000000000009DD"
]
},
"volumes": [
"*all"
],
"allow_unsupported": true
}
Upvotes: 1