简体   繁体   中英

There is a way to send json string or even JSONObject to POSTMAN without a slash before every double quote?

After alot of research i knew that JAVA does that internally. Tried to replace the slashes with empty string.Also tried to use some libraries to parse String to JSONObject But Same result, A slash before every double qoute..

Request To POSTMAN:


    {
        "MTI": "0100",
        "2": "4655206331051889",
        "3": "000000",
        "4": "000000012300",
        "7": "0321054133",
        "11": "001205",
        "14": "0325",
        "18": "5399",
        "22": "022",
        "25": "00",
        "35": "2312312332",
        "37": "206305000014",
        "41": "29110001",
        "42": "1001001",
        "49": "840",
        "transactionid": "12",
        "co-ordinates": "3042304,293572945"
    }

Code:


        StringBuilder transactionReq = new StringBuilder();
              for (Object o : responseMessage.getChildren().keySet()) {
                int key = (Integer) o;
        
                // The Transaction Request Body that has been Received in JSON Format.
                transactionReq
                    .append('"')
                    .append(key)
                    .append('"')
                    .append(" : ")
                    .append('"')
                    .append(responseMessage.getValue(key))
                    .append('"')
                    .append(" ,");
              }
              transactionReq
                  .insert(0, "{")
                  .deleteCharAt(transactionReq.length() - 1)
                  .deleteCharAt(transactionReq.length() - 1)
                  .insert(transactionReq.length(), "}");
              response.setMessage(transactionReq.toString().replaceAll("\\\\", ""));
    System.out.println(transactionReq.toString());

Console:


    {
        "message": "{"0" : "0110" ,"1" : "4655206331051889" ,"3" : "000000" ,"4" : "000000012300" ,"6" : "000000000012" ,"7" : "0321054133" ,"11" : "001205" ,"14" : "0325" ,"18" : "5399" ,"22" : "022" ,"25" : "00" ,"35" : "2312312332" ,"37" : "549684      " ,"38" : "84738 " ,"39" : "00" ,"41" : "29110001" ,"42" : "1001001        " ,"49" : "840" ,"57" : "3042304" ,"58" : "293572945"}"
    }

Response From POSTMAN:


    {
    "message": "{\"0\" : \"0110\" ,\"2\" : \"4655206331051889\" ,\"3\" : \"000000\" ,\"4\" : \"000000012300\" ,\"6\" : \"000000000012\" ,\"7\" : \"0321054133\" ,\"11\" : \"001205\" ,\"14\" : \"0325\" ,\"18\" : \"5399\" ,\"22\" : \"022\" ,\"25\" : \"00\" ,\"35\" : \"2312312332\" ,\"37\" : \"549684      \" ,\"38\" : \"84738 \" ,\"39\" : \"00\" ,\"41\" : \"29110001\" ,\"42\" : \"1001001        \" ,\"49\" : \"840\" ,\"57\" : \"3042304\" ,\"58\" : \"293572945\"}"
    }

The Output in the console proves that iam sending a right json request.. But the response the shows in postman says the opposite.. Happy to hear any Explanation... Thanks in Advance

It`s built in java, Java treats Strings that way, So i used a DTO To avoid that

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM