I encountered this error when I tried to apply toJson method on a json construct.
I had the following json construct. Let me say this as "x"
{"menuItems": [
{
"serialNumber": 1,
"Label": "Label_1",
"Link":"Link_1",
"subMenuItems": [
{
"serialNumber": 1,
"Label": "Label_1",
"Link":"Link_1",
"subMenuItems": [
,
]
},
]
},
]}
When i attempted some thing like toJson(x), I got the FBSUndefined error. How ever, when I attempted, fromJson(x) I got sort of I got the following error
Error when parsing JSON string
Encountered " "object "" at line 1, column 2. Was expecting one of: "false" ... "null" ... "true" ...blah blah blah
Encountered " "object "" at line 1, column 2. Was expecting one of: "false" ... "null" ... "true" ...blah blah blah
When I just put my json construct on to a field's default value and tried to parse the field's value using the following code
x=getComponent("toJsonTest").getValue();
y=fromJson(x);
getComponent("result").setValue(y.menuItems.length)//-> result was 2.0 (i guess)
it worked like charm. Voilay=fromJson(x);
getComponent("result").setValue(y.menuItems.length)//-> result was 2.0 (i guess)
I understand that this must be sort of, a beginner level stuff for Json in XPages.
If you would like to be saddened further by coding a lot to obtain perfection, may be you can explore "com.ibm.commons.util.io.json" and use them in your SSJS :P