首页 > 解决方案 > 如果 json 字符串包含 utf 8 个字符,则响应仅在 java 中给出一半数据

问题描述

这是预期结果。它适用于英文字符。

我遇到了问题如果 json String 包含任何其他语言字符,如日语、telegu 等。

我尝试使用 Print Writer 和 Base64 编码器等。但没有用帮助我解决这个问题

    {  
   "categoryItems":{  
      "Dry Clean1":[  
         {  
            "id":3589,
            "name":"చొక్కా",
            "shortDescription":"",
            "salesRate":0,
            "image":"",
            "igst":5,
            "cgst":5,
            "sgst":5,
            "state":"ACTIVE",
            "value0":"1",
            "value1":"Yes",
            "value2":"",
            "productposition":0,
            "type":"Goods",
            "stockInHand":0,
            "hsnCode":"",
            "tags":"",
            "catalog":"Dry clean",
            "catalogCategory":"Dry Clean1",
            "categoryId":697,
            "color":"#00f7ff",
            "txtColor":"#000000",
            "groupId":0
         },
         {  
            "id":3590,
            "name":"Trouser",
            "shortDescription":"",
            "salesRate":0,
            "image":"https://s3.ap-south-1.amazonaws.com/fkorg48//tie_coloring_page.png",
            "igst":5,
            "cgst":5,
            "sgst":5,
            "state":"ACTIVE",
            "value0":"1",
            "value1":"Yes",
            "value2":"",
            "productposition":0,
            "type":"Goods",
            "stockInHand":0,
            "tags":",noPrint",
            "catalog":"Dry clean",
            "catalogCategory":"Dry Clean1",
            "categoryId":697,
            "color":"#00f7ff",
            "txtColor":"#000000",
            "groupId":0
         },
         {  
            "id":3591,
            "name":"Jeans",
            "shortDescription":"",
            "salesRate":0,
            "image":"fk_jeans",
            "igst":5,
            "cgst":5,
            "sgst":5,
            "state":"ACTIVE",
            "value0":"1",
            "value1":"Yes",
            "value2":"",
            "productposition":0,
            "type":"Goods",
            "stockInHand":0,
            "tags":"",
            "catalog":"Dry clean",
            "catalogCategory":"Dry Clean1",
            "categoryId":697,
            "color":"#00f7ff",
            "txtColor":"#000000",
            "groupId":0
         },
         {  
            "id":3592,
            "name":"Top",
            "shortDescription":"",
            "salesRate":0,
            "image":"https://s3.ap-south-1.amazonaws.com/fkcustomer2468//ASSETPRODUCT/3592/top_1535197675847.png",
            "igst":5,
            "cgst":5,
            "sgst":5,
            "state":"ACTIVE",
            "value0":"1",
            "value1":"No",
            "value2":"",
            "productposition":0,
            "type":"Goods",
            "stockInHand":0,
            "tags":"",
            "catalog":"Dry clean",
            "catalogCategory":"Dry Clean1",
            "categoryId":697,
            "color":"#00f7ff",
            "txtColor":"#000000",
            "groupId":0
         },
         {  
            "id":3593,
            "name":"Saree",
            "shortDescription":"",
            "salesRate":50,
            "image":"fk_saree",
            "igst":5,
            "cgst":5,
            "sgst":5,
            "state":"ACTIVE",
            "value0":"1",
            "value1":"No",
            "value2":"",
            "productposition":0,
            "type":"Goods",
            "stockInHand":0,
            "tags":"",
            "catalog":"Dry clean",
            "catalogCategory":"Dry Clean1",
            "categoryId":697,
            "color":"#00f7ff",
            "txtColor":"#000000",
            "groupId":0
         },
         {  
            "id":16393,
            "name":"1kg",
            "salesRate":300,
            "image":"",
            "cgst":5,
            "sgst":5,
            "state":"ACTIVE",
            "value0":"40",
            "value1":"No",
            "value2":"",
            "productposition":0,
            "type":"Goods",
            "stockInHand":0,
            "hsnCode":"",
            "tags":"salesInfo,noPrint,noCount",
            "catalog":"Dry clean",
            "catalogCategory":"Dry Clean1",
            "categoryId":697,
            "color":"#00f7ff",
            "txtColor":"#000000",
            "groupId":0
         },
         {  
            "id":3594,
            "name":"Blazer",
            "shortDescription":"",
            "salesRate":100,
            "image":"https://s3.ap-south-1.amazonaws.com/fkcustomer48//ASSETPRODUCT/2692/lazer_1534504840207.png",
            "igst":5,
            "cgst":5,
            "sgst":5,
            "state":"ACTIVE",
            "value0":"1",
            "value1":"No",
            "value2":"",
            "productposition":0,
            "type":"Goods",
            "stockInHand":0,
            "tags":"",
            "catalog":"Dry clean",
            "catalogCategory":"Dry Clean1",
            "categoryId":697,
            "color":"#00f7ff",
            "txtColor":"#000000",
            "groupId":0
         },
         {  
            "id":3595,
            "name":"Skirt Pleated",
            "shortDescription":"",
            "salesRate":55,
            "image":"fk_skirt_pleated",
            "igst":5,
            "cgst":5,
            "sgst":5,
            "state":"ACTIVE",
            "value0":"1",
            "value1":"No",
            "value2":"",
            "productposition":0,
            "type":"Goods",
            "stockInHand":0,
            "tags":"",
            "catalog":"Dry clean",
            "catalogCategory":"Dry Clean1",
            "categoryId":697,
            "color":"#00f7ff",
            "txtColor":"#000000",
            "groupId":0
         },

      ]

   },

   "taxes":[  
      {  
         "description":"",
         "id":31,
         "name":"CGST",
         "rate":5,
         "selectable":false,
         "systemTax":false,
         "tags":"",
         "taxClass":"SI",
         "taxType":null,
         "taxes":"",
         "uniqueCode":"CGST",
         "version":0
      },
      {  
         "description":"",
         "id":32,
         "name":"SGST",
         "rate":5,
         "selectable":false,
         "systemTax":false,
         "tags":"",
         "taxClass":"SI",
         "taxType":null,
         "taxes":"",
         "uniqueCode":"SGST",
          "version":0
      }
     ]
    }

这是实际结果它只显示半个 json 字符串。我怎么解决这个问题。

    {  
   "categoryItems":{  
      "Dry Clean1":[  
         {  
            "id":3589,
            "name":"చొక్కా",
            "shortDescription":"",
            "salesRate":0,
            "image":"",
            "igst":5,
            "cgst":5,
            "sgst":5,
            "state":"ACTIVE",
            "value0":"1",
            "value1":"Yes",
            "value2":"",
            "productposition":0,
            "type":"Goods",
            "stockInHand":0,
            "hsnCode":"",
            "tags":"",
            "catalog":"Dry clean",
            "catalogCategory":"Dry Clean1",
            "categoryId":697,
            "color":"#00f7ff",
            "txtColor":"#000000",
            "groupId":0
         },
         {  
            "id":3590,
            "name":"Trouser",
            "shortDescription":"",
            "salesRate":0,
            "image":"https://s3.ap-south-1.amazonaws.com/fkorg48//tie_coloring_page.png",
            "igst":5,
            "cgst":5,
            "sgst":5,
            "state":"ACTIVE",
            "value0":"1",
            "value1":"Yes",
            "value2":"",
            "productposition":0,
            "type":"Goods",
            "stockInHand":0,
            "tags":",noPrint",
            "catalog":"Dry clean",
            "catalogCategory":"Dry Clean1",
            "categoryId":697,
            "color":"#00f7ff",
            "txtColor":"#000000",
            "groupId":0
         },
         {  
            "id":3591,
            "name":"Jeans",
            "shortDescription":"",
            "salesRate":0,
            "image":"fk_jeans",
            "igst":5,
            "cgst":5,
            "sgst":5,
            "state":"ACTIVE",
            "value0":"1",
            "value1":"Yes",
            "value2":"",
            "productposition":0,
            "type":"Goods",
            "stockInHand":0,
            "tags":"",
            "catalog":"Dry clean",
            "catalogCategory":"Dry Clean1",
            "categoryId":697,
            "color":"#00f7ff",
            "txtColor":"#000000",
            "groupId":0
         },
         {  
            "id":3592,
            "name":"Top",
            "shortDescription":"",
            "salesRate":0,
            "image":"https://s3.ap-south-1.amazonaws.com/fkcustomer2468//ASSETPRODUCT/3592/top_1535197675847.png",
            "igst":5,
            "cgst":5,
            "sgst":5,
            "state":"ACTIVE",
            "value0":"1",
            "value1":"No",
            "value2":"",
            "productposition":0,
            "type":"Goods",
            "stockInHand":0,
            "tags":"",
            "catalog":"Dry clean",
            "catalogCategory":"Dry Clean1",
            "categoryId":697,
            "color":"#00f7ff",
            "txtColor":"#000000",
            "groupId":0
         },
         {  
            "id":3593,
            "name":"Saree",
            "shortDescription":"",
            "salesRate":50,
            "image":"fk_saree",
            "igst":5,
            "cgst":5,
            "sgst":5,
            "state":"ACTIVE",
            "value0":"1",
            "value1":"No",
            "value2":"",
            "productposition":0,
            "type":"Goods",
            "stockInHand":0,
            "tags":"",
            "catalog":"Dry clean",
            "catalogCategory":"Dry Clean1",
            "categoryId":697,
            "color":"#00f7ff",
            "txtColor":"#000000",
            "groupId":0
         },
         {  
            "id":16393,
            "name":"1kg",
            "salesRate":300,
            "image":"",
            "cgst":5,
            "sgst":5,
            "state":"ACTIVE",
            "value0":"40",
            "value1":"No",
            "value2":"",
            "productposition":0,
            "type":"Goods",
            "stockInHand":0,
            "hsnCode":"",
            "tags":"salesInfo,noPrint,noCount",
            "catalog":"Dry clean",
            "catalogCategory":"Dry Clean1",
            "categoryId":697,
            "color":"#00f7ff",
            "txtColor":"#000000",
            "groupId":0
         },
         {  
            "id":3594,
            "name":"Blazer",
            "shortDescription":"",
            "salesRate":100,
            "image":"https://s3.ap-south-1.amazonaws.com/fkcustomer48//ASSETPRODUCT/2692/lazer_1534504840207.png",
            "igst":5,
            "cgst":5,
            "sgst":5,
            "state":"ACTIVE",
            "value0":"1",
            "value1":"No",
            "value2":"",
            "productposition":0,
            "type":"Goods",
            "stockInHand":0,
            "tags":"",
            "catalog":"Dry clean",
            "catalogCategory":"Dry Clean1",
            "categoryId":697,
            "color":"#00f7ff",
            "txtColor":"#000000",
            "groupId":0
         },
         {  
            "id":3595,
            "name":"Skirt Pleated",
            "shortDescription":"",
            "salesRate":55,
            "image":"fk_skirt_pleated",
            "igst":5,
            "cgst":5,
            "sgst":5,
            "state":"ACTIVE",
            "value0":"1",
            "value1":"No",
            "value2":"",
            "productposition":0,
            "type":"Goods",
            "stockInHand":0,
            "tags":"",
            "catalog":"Dry clean",
            "catalogCategory":"Dry Clean1",
            "categoryId":697,
            "color":"#00f7ff",
            "txtColor":"#000000",
            "groupId":0
         },

      ]

   },

   "taxes":[  
      {  
         "description":"",
         "id":31,
         "name":"CGST",
         "rate":5,
         "selectable":false,
         "systemTax":false,
         "tags":"",
         "taxClass":"SI",
         "taxType":null,
         "taxes":"",
         "uniqueCode":"CGST",
         "version":0
      },
      {  
         "description":"",
         "id":32,
         "name":"SGST",
         "rate":5,
         "selectable":false,
         "systemTax":false,
         "tags":"",
         "taxClass":"SI",
         "taxType":null,
         "taxes":"",
         "uniqueCode":"SGST",
          "

这是我的服务器代码

OutputStream out = null;
String jsonData = jsonObj.toString();
out = response.getOutputStream();
response.setContentLength(jsonData.length());
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Headers", "Content-Type");
response.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
out.write(jsonData.getBytes(StandardCharsets.UTF_8);
out.flush();

标签: javascriptjavaajax

解决方案


推荐阅读