Pages

Thursday, October 31, 2013

JSON Issues in XPages - Unknown literal of class com.ibm.jscript.types.FBSUndefined

This post does not speak about any fixes for this error message, however, contains a tip that will help avoid the issue.

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

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. Voila

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

1 comment:

  1. Thanks for the post, I am techno savvy. I believe you hit the nail right on the head.
    I am highly impressed with your blog. It is very nicely explained.
    Your article adds best knowledge to our Java Online Training from India. or learn thru Java Online Training from India Students.

    ReplyDelete