I receive this json through a request
{"pay_CCIban":"XXX",
"pay_bic":"YYY",
"pay_names[]":["name one","name two"],
"pay_extid":"extId"}
I'm trying to deserialize it with this class
global class Famrs{
global class datajsonweb{
global String pay_CCIban {get; set;}
global String pay_bic {get; set;}
global List<String> pay_names {get; set;}
global String pay_extid {get; set;}
}
datajsonweb data = (datajsonweb)JSON.deserialize(requestBody.toString(),datajsonweb.class);
Integer lstSize = data.pay_names.size(); //I get nullpointer here
...
}
I get an attempt to de-reference null object when I try to get the size of the array inside the json, i don't know what I'm doing wrong
Any help?
Thanks in advance
EDIT:
Like sfdcfox says, the "pay_names[]" key in the json needs to be like "pay_names" so I'm trying to do a replaceAll('[]','') but I'm getting: Invalid regex: Unclosed character class. If I try to escape the brackets I get: Illegal string literal.
Is it possible to remove the brackets in the json?
Thanks again
EDIT 2:
Thanks to Jesse Milburn's comment it works.
json
object contains data for that field? Or even contains that field? If the field is empty (or doesn't exist) the deserializer will not instantiate an empty list.pay_names
json variable is called"pay_names[]"
? Shouldn't it be"pay_names"
?