c# - Handling double quotes in JSON strings -
we have application knockout , facing problem registers in database have double quotes, caused json parsing fail.
here's json not valid due rogue double quote:
{ "optionsummaries": [ { "id": 110, "name": "option 1", "status": 1, "productgroupnodes": [ { "id": 110, "name": "corporate brand reputation", "status": 2, "waves": [ { "id": 110, "name": "wave 1", "status": 2, "services": [ { "id": 1101, "title": "proposal budget owner service", "currencycode": "usd", "estimatedcost": 177.0000, "creationdatetime": "/date(1437472898503)/", "status": 2 } ] } ] }, { "id": 111, "name": "2013 consumer scan", "status": 1, "waves": [ { "id": 111, "name": "wave 1", "status": 1, "services": [ { "id": 1111, "title": "proposal budget owner service", "currencycode": "usd", "estimatedcost": 0.0000, "creationdatetime": "/date(1437472898503)/", "status": 1 } ] } ] } ] }, { "id": 115, "name": "option 2", "status": 1, "productgroupnodes": [ { "id": 115, "name": "corporate brand reputation", "status": 1, "waves": [ { "id": 115, "name": "wave 1", "status": 1, "services": [ { "id": 1151, "title": "proposal budget owner service", "currencycode": "usd", "estimatedcost": 0.0000, "creationdatetime": "/date(1437472898503)/", "status": 1 } ] } ] }, { "id": 116, "name": "2013 consumer scan", "status": 1, "waves": [ { "id": 116, "name": "wave 1", "status": 1, "services": [ { "id": 1161, "title": "proposal budget owner service", "currencycode": "usd", "estimatedcost": 0.0000, "creationdatetime": "/date(1437472898503)/", "status": 1 } ] } ] } ] } ], "servicecostsedit": { "serviceid": 1101, "servicename": "proposal budget owner service", "servicecurrencyisocode": "usd", "servicelegalentitycode": "0310", "laborhourcostspanel": { "laborhourcosts": [ { "id": 2, "costcenters": [ { "disabled": false, "group": null, "selected": false, "text": "3101010001 - consumer kam group", "value": "3101010001" }, { "disabled": false, "group": null, "selected": false, "text": "3102510255 - knowledge panel", "value": "3102510255" } ], "fiscalyears": [ { "disabled": false, "group": null, "selected": false, "text": "2013", "value": "2013" } ], "laborgrades": [ { "code": "0hl002", "currencycode": "usd", "rate": 44.0000, "disabled": false, "group": null, "selected": false, "text": "0hl002 - 44.00/hr usd", "value": "0hl002" } ], "selectedlaborgradecostcenter": "3101010001", "selectedlaborgradefiscalyear": 2013, "selectedlaborgradecode": "0hl002", "selectedlaborgraderate": 44.0000, "setuphours": 2.00, "managementhours": 1.00, "deliveryhours": 1.00, "isempty": false } ], "laborhourcostscostcenterdatasource": [ { "disabled": false, "group": null, "selected": false, "text": "3101010001 - consumer kam group", "value": "3101010001" }, { "disabled": false, "group": null, "selected": false, "text": "3102510255 - knowledge panel", "value": "3102510255" } ], "defaultcostcentercodeforinitialemptyrecord": null, "defaultfiscalyearforinitialemptyrecord": null, "overheadcosts": [ { "laborgradecostcentercode": "3101010001", "laborgradefiscalyear": 2013, "overheadrate": 0.0000, "setuphours": 2.00, "managementhours": 1.00, "deliveryhours": 1.00 } ], "overheadcostsvisible": true, "overheadcostsinitialdatasource": [ { "key": { "costcentercode": "3101010001", "fiscalyear": 2013 }, "value": { "code": "0ho001", "currencycode": "usd", "rate": 0.00, "disabled": false, "group": null, "selected": false, "text": "0ho001 - usd 0.00/hr", "value": "0ho001" } } ], "costcenter": "f2f papi", "servicecurrencyisocode": "usd", "editingallowed": true }, "vendorcostspanel": { "vendorcosts": [ { "id": 132, "selectedcostelementcode": "1992000004", "vendorcode": "", "vendorname": null, "description": "doublequotes"","directcostattachment":null,"quantity":1,"vendorrate":1.0000,"isempty":false}],"costelements":[{"disabled":false,"group":null,"selected":false,"text":"externalsuppliercosts","value":"1992000004"},{"disabled":false,"group":null,"selected":false,"text":"licensesfromaffilitatedcompanies","value":"1992000002"}],"servicecurrencyisocode":"usd","editingallowed":true},"costingassumptionspanel":{"description":"","editingallowed":true},"servicespecificationspanel":{"title":"proposalbudgetownerservice","type":"proposalbudgetownerservice","fields":[{"value":"hellolonglonglongtext...","id":153,"code":"overview","title":"overview","isrequiredforcosting":false,"dependencyvisibilityexpression":null,"fieldcodestoreevaluateonchange":[],"editingallowed":false}]},"approvalcomments":{"commenttype":0,"message":null,"approvername":null,"approveremail":null,"anycomments":false},"rejectedcostinfovisible":false,"editingallowed":true},"submitcostsenabled":true,"editingallowed":false,"selectedtreenode":{"id":1101,"type":3},"proposal":{"proposalid":11,"proposalname":"ad-hocatcostingonmain","proposalcostcentercode":"3102510220","proposalvalid":{"isvalid":true,"errormessage":""},"soldtocustomer":"jennifersamson","expectedprojectstartdate":"/date(1426892400000)/","expectedprojectenddate":"/date(1431208800000)/","functionalityareaenabled":true}}
if test json against jsonlint see problem lies. best way handle this? think way i'm serializing c# model json not proper? use:
var jsonmodel = jsonconvert.serializeobject(model);
any appreciated.
edit
issue fixed. problem serialization.
i fixed using method httputility.javascriptstringencode
var jsonviewmodel = httputility.javascriptstringencode(json.encode(model));
this solved problem. had pass knockout @html.raw(jsonviewmodel)
best regards , everyone!
daniel
Comments
Post a Comment