我有一个JSON,我必须使用JSON.Parse读取我能够成功完成的值。问题是在一个条件下,当我在http://jsonlint.com/.So计划中测试时,关键的CurrentAddress无效只检索此值,然后从JSON中删除它。我检查了堆栈溢出并获取代码以检索值。但是我收到错误 “无法获取属性'CurrentAddress'的值:对象为null或未定义。我知道该对象为null或未定义但当我看到代码时,对象将填充以下JSON详细信息
{"CardDetails":{"NameEn":"HASSAN ",
"NameAr":"حسن سالم راشد البطاشي",
"CardID":"099778",
"CardType":"Citizen",
"CardExpiryDate":"25/11/2017",
"BirthDate":"19/08/1980",
"CountryBirthAr":"سلطنة عمان",
"TownOfBirthAr":"مسقط",
"NationalityEn":"OMANI",
"NationalityAr":"عماني",
"GenderEn":"Male",
"GenderAr":"ذكر",
"OccupationEn":"OFFICE CLERK - GENERAL",
"OccupationAr":"كاتب اداري / عام",
"SponsorNameEn":"",
"SponsorNameAr":"",
"PassportNo":"٠٢٣٦٦٢٠٣",
"PassportExpiryDate":"02/03/2019",
"PassportIssueDate":"03/03/2009",
"PassportCountry":"سلطنة عمان",
"VisaNo":"",
"VisaIssueDate":"",
"VisaExpiryDate":"",
"CurrentAddress":"
المزارع, قـريات
الصندوق البريدي 3168, الرمز البريدي 112",
"CSN":"21400052F296F",
"SAMCSN":"5900002163C73",
"ErrorDescription":""}}
我的Javascript是:
var jsonString = myAx1.readCardJSON();
var a = jsonString["CardDetails"].CurrentAddress;
alert(a);
在这种情况下,我无法使用JSON.Parse,因为currentaddress值显示为无效
答案 0 :(得分:0)
以下代码有助于删除\ n
var myJSONString = jsonString.replace(/ [\ n \ r \ n] / gi,'')