You need to sign in to do that
Don't have an account?
Vidhya K 14
JsonGenerator class
Hi,
I'm trying to input value which is an array index inside JSONGenerator class. I'm not sure how to represent this. Can anyone help me on this.
Json syntax: "excludedDocuments": ["2"]
JSONGenerator: gen.writeStringField('excludedDocuments', ['2']);
When I give this as array, it throws error. Is there any other format to be used? Please suggest.
Regards,
Vidhya
I'm trying to input value which is an array index inside JSONGenerator class. I'm not sure how to represent this. Can anyone help me on this.
Json syntax: "excludedDocuments": ["2"]
JSONGenerator: gen.writeStringField('excludedDocuments', ['2']);
When I give this as array, it throws error. Is there any other format to be used? Please suggest.
Regards,
Vidhya
Please make sure that you have a clear JSON syntax. Because for an array you need a key -> value pair and in the above question you just have a value.
Sample format
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject();
gen.writeFieldName('excluded Documents');
gen.writeStartArray();
gen.writeStartObject();
gen.writeStringField('id','2');
gen.writeEndObject();
gen.writeEndArray();
gen.writeEndObject();
string n = gen.getAsString();
system.debug('gens string'+ n);
output
gens string :
{
"excluded Documents" : [ { "id" : "2" } ]
}
hope this would be of any help..!!