The Object
type is not really something we can use directly in Apex. I don't believe it has any fields/properties, and only has a few known (but undocumented) methods.
The generally preferred approach to deserializing JSON in Apex is to create a series of classes that match the structure of the JSON you're trying to deserialize.
In this case, that would look something like this:
public class MyJsonData{
public List<Id> proposalIds;
public Boolean response;
}
// Even though we're telling JSON.deserialize() to use MyJsonData as a template
// of sorts, it always returns an Object, so we need to do a little type-casting
MyJsonData data = (MyJsonData)JSON.deserialize(response, MyJsonData.class);
// When working with booleans, there is no need to test for equality to true
// (or false, either).
System.assert(data.response);
JSON.deserializeUntyped()
is generally used when your JSON data contains something problematic for Salesforce like a reserved word (break, continue, switch) or things like __c
.
deserializeUntyped() also returns an Object, but it actually is either a Map<String, Object>
or a List<Object>
, depending on whether the topmost element in the JSON is a (JSON) object or a list. In your case, you'd get a Map<String, Object>
.
Using a Map<String, Object>
can involve a lot of extra type-casting (which is why at least I prefer defining classes for the deserialization), but in your case would be fairly simple.
Map<String, Object> data = (Map<String, Object>)JSON.deserializeUntyped(response);
Boolean jsonResponse = (Boolean)data.get('response');
System.assert(jsonResponse);