2016-10-17 19 views
0

如何刪除這些反轉的「」,當我對Json對象進行字符串化時自動創建。如何刪除在stringify函數中創建的「倒過來」?

{"entityList":["{"Scenario No":"SC1","Accounting Mon Extracted":"null","Acronym":"null","Address1":"542","Address2":"null","AddressType 

,然後在下一場景開始還有另外一個「」,這正在形成......我想這是在這種類型的,這樣我可以通過它張貼到服務器...

{ 
    "entityList": [ 
    { 
     "scenarioNo": "SC1", 
     "accountingMonExtracted": null, 
     "acronym": null, 
     "address1": "542 W 27th Street 4th Floor", 
     "address2": null, 
     "addressType": "MAILING", 
     "alternateEmailId": null, 
     "alternateFaxNo": null, 
    "alternatePhoneNo": null, 
     "city": "Bethlehem", 
     "country": "US", 
     "county": null, 
     "firstName": "Thomas", 
     "fullName": "Peter Jen", 
     "lastName": "Routher", 
     "middleName": null, 
     "namePrefix": null, 
     "nameSuffix": null, 
     "primaryAddressYN": "Y", 
     "primaryEmailId": "[email protected]", 
     "primaryFaxNo": "(406)485-2983", 
     "primaryPhoneNo": "(405)452-3645", 
     "state": "AB", 
     "zipCode": "40007.0", 
     "agentType": null, 
     "autoCommClosingDays": null, 
     "autoCommExtractionYN": null, 
     "billingContactName": "Peter Jen", 
     "commissionCurrency": null, 
     "commissionEFTTokenId": null, 
     "commissionEntityYN": null, 
     "commissionPayeeEntityCode": null, 
     "commissionPayeeEntityType": null, 
     "commissionPaymentMethod": null, 
     "commissionStatementEntityCode": null, 
     "commissionStatementEntityType": null, 
     "creditTermDays": null, 
     "creditTermMonths": null, 
     "customerNo": null, 
     "doingBusinessAsName": null, 
     "eftDraftOption": null, 
     "entityType": "INSURED", 
     "frequencyDayMonth": null, 
     "frequencyDayOfWeek": null, 
     "frequencyType": null, 
     "invoiceCurrency": "USD", 
     "ncanGraceDays": null, 
     "outputDeliveryMethod": "M", 
     "parentEntityCode": null, 
     "paymentMethod": "EFT", 
     "process1099Indicator": "N", 
     "recurringEFTTokend": null, 
     "requestedDueDay": null, 
     "sourceSystem": "DPAS", 
     "sourceSystemEntityCode": "INS000020", 
     "statementFormat": null, 
     "statementIndicatorYN": "N", 
     "statementMailingDay": null, 
     "userRemarks": null, 
     "vendorCode": null, 
     "ssn": null, 
     "taxid": null 
    }, 
    { 
     "scenarioNo": "SC2", 
     "accountingMonExtracted": null, 
     "acronym": null, 
     "address1": "542 W 27th Street 4th Floor", 
     "address2": null, 
     "addressType": "MAILING", 
     "alternateEmailId": null, 
     "alternateFaxNo": null, 
     "alternatePhoneNo": null, 
     "city": "Bethlehem", 
     "country": "US", 

我在JavaScript代碼如下...

var row = {}; 
var insured=[]; 
var a; 
var row1 = {}; 
var insured1=[]; 
var a1; 
function creatJsonobj(){ 
    var cols = $("#policytable thead tr th").map(function(){ 
     return $(this).text() 
    }) 
    var tableObject = $("#policytable tbody tr").map(function(i) { 

     $(this).find("td").each(function(i) { 
      var rowName = cols[i]; 
//   console.log(rowName); 
      row[rowName] = $(this).find('input').val(); 
      a= JSON.stringify(row); 
     }) 

//  console.log("entity table : "+a); 

     insured.push(a); 
//  console.log(insured);     
     return row; 
    }); 
    for(var i in insured){ 
     var cli = JSON.parse(insured[i]); 
//  console.log(cli); 
    } 

    var entityObj = {entityList: insured} ; 
    console.log(JSON.stringify(entityObj).replace(/\\/g, '')); 


    $("#entityTable").empty(); 
     var cols1 = $("#paymenttable thead tr th").map(function(){ 
     return $(this).text() 
    }) 
    var tableObject = $("#paymenttable tbody tr").map(function(i) { 

     $(this).find("td").each(function(i) { 
      var rowName = cols1[i]; 
//   console.log(rowName); 
      row1[rowName] = $(this).find('input').val(); 

      a1= JSON.stringify(row1); 
     }) 
//  console.log("payment table : "+a1); 

     insured1.push(a1); 

     return row1; 
    }); 
    for(var i in insured1){ 
     var cli = JSON.parse(insured1[i]); 

    } 

    var paymentObj = {paymentList:insured1} ; 
/* var C=JSON.stringify(sendJson1); 
    var finalData = C.replace(/\\/g, ''); 
alert(finalData); 
    console.log(finalData);*/ 
    console.log(paymentObj); 

    var billing = {entityObj,paymentObj}; 
    console.log(billing); 

如何做到這一點?....

+0

您可以使用' 「」',而不是'null'和問題解決 – Rajesh

+0

'A = JSON.stringify(行);'應該發生在你的'.each()'循環之外。 – PHPglue

回答

1

當您字符串化row,它現在是string,而不是object

你的道:

var row = JSON.stringify({key:value}); // which return a string 
var object = {entityList: [row]}; 
console.log(JSON.stringify(object)); // which inputs "{entityList: ["{"key":"value"}"]}" 

正確方法:

var object = {entityList: [row]}; 
console.log(JSON.stringify(object)); 
相關問題