java - Creating Json from XAgent -


i'm trying create json xpages "xagent" using java. there's particular format i'm trying , uses integer key , keep getting errors don't understand.

here's example error: caused by: java.lang.classcastexception: java.lang.integer incompatible java.lang.string @ com.ibm.commons.util.io.json.jsongenerator$generator.outobject(jsongenerator.java:202) @ com.ibm.commons.util.io.json.jsongenerator$generator.outliteral(jsongenerator.java:163) @ com.ibm.commons.util.io.json.jsongenerator$generator.outliteral(jsongenerator.java:142) @ com.ibm.commons.util.io.json.jsongenerator$generator.tojson(jsongenerator.java:138) @ com.ibm.commons.util.io.json.jsongenerator.tojson(jsongenerator.java:64) @ com.ibm.commons.util.io.json.jsongenerator.tojson(jsongenerator.java:49)

i'm trying create json output this:

[   {      // minimum       0:{src:'item_one_format_one.ext', type: 'video/...'}        },   {      // 1 content, multiple formats      0:{src:'item_two_format_one.ext', type: 'video/...'},      1:{src:'item_two_format_two.ext', type: 'video/...'}   },   {      // 1 content, multiple formats, item specific config      0:{src:'item_three_format_one.ext', type: 'video/...'},      1:{src:'item_three_format_two.ext', type: 'video/...'},      3:{src:'item_three_format_three.ext', type: 'video/...'},      4:{src:'item_three_format_four.ext', type: 'video/...'},                config: {         option1: value1,         option2: value2      }  ]       

not multiple "objects" , last 1 seems combination of integer , string key value.

here code tried , got working kinda of:

public string testlist() throws jsonexception, ioexception {          integer count = 0;          map<string, object> containermap = new treemap<string, object>();         system.out.println("a");           treemap<string, string> stringmap = new treemap<string, string>();         system.out.println("b");         stringmap.put("one", "value1");         stringmap.put("two", "value2");         system.out.println("c");          containermap.put("1", "one");         count++;         containermap.put("2", "two");         count++;         containermap.put("3", "three");          system.out.println("d");          string json = jsongenerator.tojson(new jsonjavafactory(), containermap);         system.out.println("e");         return json;      } 

this code produces:

{     "1": "zero",     "2": "one",     "3": "two" } 

note quotes key value. assume that's going problem. enable integers in key. , i'm not sure how mix integers string seen in 3rd object example.

any advice appreciated. thanks!

it cannot used integer in way: {0: {...}} properties supposed strings: {"0": {...}}

maybe need array instead:

{ // 1 content, multiple formats, item specific config videolist: [ {src:'item_three_format_one.ext', type: 'video/...'}, {src:'item_three_format_two.ext', type: 'video/...'}, {src:'item_three_format_three.ext', type: 'video/...'}, {src:'item_three_format_four.ext', type: 'video/...'} ], vidoconfig: { option1: value1, option2: value2 } }

regards, txemanu


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -