0

I pass the value from the controller in this way:

  requ.setAttribute("xmlData",JSONObject.fromObject(vedioService.getXmlData(cameraUuid))); 

And in the jsp file I can console.log the xmlData, but when I want to parse it to the json object, it fails? How should I change my code? I want to get the xmlData.data. The console.log() result is:

 {"data":"<?xml version="1.0" encoding="UTF-8"?><previewInfo><camera     installPosition="0" supportFishEye="0" extraSupport="0" url="rtsp://192.168.1.2:554/hikvision://192.138.1.1:8000:0:0? cnid=4&amp;pnid=4&amp;username=1&amp;password=2"  sysCode="df32d5eaf78549bea4789ec492f32c59" name="name1"/><presetlist/></previewInfo>","errorMessage":"fetchPreviewXml success!","errorCode":0}

My js code is :

  console.log('${xmlData}');  
  var xmlDataObj= $.parseJSON('${xmlData}'); //error: SCRIPT1009: 缺少 '}'
  playByXmlData(xmlDataObj.data);

If I return the data like this, it can parse the json.

     {"data":"myData","errorMessage":"fetchPreviewXml success!","errorCode":0}
Statik Stasis
  • 308
  • 1
  • 5
  • 16
flower
  • 2,212
  • 3
  • 29
  • 44

0 Answers0