I am trying to eval() a json having speacial characters - 
 and getting "unterminated string literal" error in Firefox 3.5.9 Although the same works fine on IE. 7. I have set the character encoding to UTF-8 in both the bro开发者_C百科wsers. Any idea why its an error in FF?
Also right before converting the String to JSON, I ran this code in java
String jsonString = //some json string having 

for(byte b : jsonString.getBytes()){
System.out.print(Integer.toHexString(b) + " ");
}
net.sf.json.JSON jsonObject = net.sf.json.JSONSerializer.toJSON(jsonString);
And the o/p for above characters is
ffffffe2 ffffff80 ffffffa8 respectively. How do I know if these are valid UTF-8 characters?
Tried using gson API for java-to-json. And works fine. Posting both the resulting jsons.
Resulting JSON using json-lib (gives unterminated string literal error)
var json = {"addToSessionFlag":false,"addToShoppingCart":false,"allMessageCodes":"IXMANAGER__PARSING_STATUS#","beanKey":"","cacheFlag":false,"callBackData":{"IXMANAGER_PARSER_ERROR_LIST":[{**"cellData":"
34295"**,"columnHeader":"","columnNumber":8,"errorMessage":"Error : Invalid Zip Code","rowNumber":1},{"cellData":"","columnHeader":"","columnNumber":9,"errorMessage":"Error : Invalid Contact Person","rowNumber":1},{"cellData":"+90-(0)212-4113838
","columnHeader":"","columnNumber":10,"errorMessage":"Error : Invalid Phone Numbers","rowNumber":1},{"cellData":"adnan.harunoglu@gdc.travel","columnHeader":"","columnNumber":12,"errorMessage":"Error : Invalid Email Address","rowNumber":1},{"cellData":"41.000792,28.802633","columnHeader":"","columnNumber":14,"errorMessage":"Error : Invalid Website","rowNumber":1},{"cellData":"15:00 p.m","columnHeader":"","columnNumber":19,"errorMessage":"Error : Invalid Hotel Check-In/Check-Out Time","rowNumber":1},{"cellData":"12:00 p.m","columnHeader":"","columnNumber":20,"errorMessage":"Error : Invalid Hotel Check-In/Check-Out Time","rowNumber":1}]}};
var test = eval(json);
alert(test);
Resulting JSON using gson (succesful eval. works!)
var json = {"keyId":0,"sSuccessType":"||ERR||","sSuccessMessage":"Parsing Failed\u003cBR /\u003e","_bAddToSessionFlag":false,"bCacheFlag":false,"success":false,"callBackData":{"IXMANAGER_PARSER_ERROR_LIST":[{"_iRowNumber":1,"_iColumnNumber":8,**"_sCellData":"\u202834295"**,"_sErrorMessage":"Error : Invalid Zip Code"},{"_iRowNumber":1,"_iColumnNumber":9,"_sErrorMessage":"Error : Invalid Contact Person"},{"_iRowNumber":2,"_iColumnNumber":9,"_sErrorMessage":"Error : Invalid Contact Person"},{"_iRowNumber":1,"_iColumnNumber":10,"_sCellData":"+90-(0)212-4113838\u2028","_sErrorMessage":"Error : Invalid Phone Numbers"},{"_iRowNumber":1,"_iColumnNumber":12,"_sCellData":"adnan.harunoglu@gdc.travel","_sErrorMessage":"Error : Invalid Email Address"},{"_iRowNumber":2,"_iColumnNumber":12,"_sCellData":"adnan.harunoglu@gdc.travel","_sErrorMessage":"Error : Invalid Email Address"},{"_iRowNumber":1,"_iColumnNumber":14,"_sCellData":"41.000792,28.802633","_sErrorMessage":"Error : Invalid Website"},{"_iRowNumber":2,"_iColumnNumber":14,"_sCellData":"40.971911,28.871362","_sErrorMessage":"Error : Invalid Website"},{"_iRowNumber":1,"_iColumnNumber":19,"_sCellData":"15:00 p.m","_sErrorMessage":"Error : Invalid Hotel Check-In/Check-Out Time"},{"_iRowNumber":2,"_iColumnNumber":19,"_sCellData":"14:00 p.m","_sErrorMessage":"Error : Invalid Hotel Check-In/Check-Out Time"},{"_iRowNumber":1,"_iColumnNumber":20,"_sCellData":"12:00 p.m","_sErrorMessage":"Error : Invalid Hotel Check-In/Check-Out Time"},{"_iRowNumber":2,"_iColumnNumber":20,"_sCellData":"12:00 p.m","_sErrorMessage":"Error : Invalid Hotel Check-In/Check-Out Time"}]}};
var test = eval(json);
alert(test);
Although this is not the complete solution to my problem as I think gson uses class variables directly instead of getters at the time of json serialization. Any thoughts about it?
精彩评论