2017-12-20 8 views
-1

메신저 json에서 URL을 얻는 것보다 json 디코딩 후에 HTML을 얻는 것보다 HTML을 가져 오는 콘텐츠 배열이있는 방식으로 URL에 게시해야합니다. 배열 키 json에 문자열을 게시하는 방법은 무엇입니까?

URL oracle = new URL(""); 
      try (BufferedReader in = new BufferedReader(
        new InputStreamReader(oracle.openStream()))) { 
       String inputLine1; 
       while ((inputLine1 = in.readLine()) != null) { 
        System.out.println(inputLine1); 
        com.eclipsesource.json.JsonObject object = Json.parse(inputLine1).asObject(); 
        com.eclipsesource.json.JsonArray items = Json.parse(inputLine1).asObject().get("data").asArray(); 

        for (JsonValue item : items) { 
         //System.out.println(item.toString()); 
         String name = item.asObject().getString("id", "Unknown Item"); 
         System.out.println(name); 

         String quantity = item.asObject().getString("url", "id"); 
         // JSONArray jsonArray2 = new JSONArray(quantity); 
         System.out.println(quantity); 

         /* Platform.runLater(() ->{ 
          try { 
           Thread.sleep(10000); 
          } catch (InterruptedException ex) { 
           Logger.getLogger(HV1.class.getName()).log(Level.SEVERE, null, ex); 
          }*/ 
         Img.load(quantity); 
           URL url; 
     InputStream is = null; 
     BufferedReader br; 
     String line; 
       url = new URL(quantity); 
      is = url.openStream(); // throws an IOException 
      br = new BufferedReader(new InputStreamReader(is)); 

      while ((line = br.readLine()) != null) { 
       System.out.println(line); 
       //byte[] postData= line.getBytes(StandardCharsets.UTF_8); 
        //String[] strArray = new String[] {line}; 
    //System.out.println(strArray[0]); 
       wb2.load(line); 
       String originalUrl = ""; 
    String newUrl = originalUrl.replace("ID", name); 
    System.out.println(newUrl); 

    URL url1 = new URL(newUrl); 
      Map<String,Object> params = new LinkedHashMap<>(); 
      params.put("content", line); 
      params.put("meta", "abc"); 


      StringBuilder postData1 = new StringBuilder(); 
      for (Map.Entry<String,Object> param : params.entrySet()) { 
       if (postData1.length() != 0) postData1.append('&'); 
       postData1.append(URLEncoder.encode(param.getKey(), "UTF-8")); 
       postData1.append('='); 
       postData1.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8")); 

      byte[] postDataBytes = postData1.toString().getBytes("UTF-8"); 

      HttpURLConnection conn = (HttpURLConnection)url1.openConnection(); 
      conn.setRequestMethod("POST"); 
      conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
      conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length)); 
      conn.setDoOutput(true); 
      conn.getOutputStream().write(postDataBytes); 

      Reader in1 = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); 

      for (int c; (c = in1.read()) >= 0;) 
       System.out.print((char)c); 

      /*   try{ 
      Thread.sleep(400); 
      }catch(InterruptedException e){System.out.println(e);} */ 
       } 
       } 
     } 
     }  

는 코드 만이 데이터에 난 내용 배열 이있는 HTML 콘텐츠를 게시 할로하지 배열에 문자열에 게시 난 내용 = html로 몸을 게시했다되는 URL에 JSON이다 페이지의? 유 URL에게 내가 (당신의 경우 HTML 문자열) 문자열을 보내려면이

+0

문제는 매우 가난하게 설명되어 있습니다. 설명하려고 더 구체적으로는 쓰레기를 자름으로써. –

+0

URL에 내용 배열에 내가 html 본문을 게시 할 필요가 –

+0

샘플 입력 및 샘플 출력을 추가하십시오. – Ganeshkumar

답변

0

즉 콘텐츠를 배열 한 번에 완료 보내야만 때마다 타격 HTML의 각 라인의 출력에서 ​​볼 수

당신은 이스케이프 문자를 사용해야합니다. '/'는 JSON의 경우 이스케이프 문자입니다. 위의 예에서

{ 
"html": "<div class=\"ad_box\"><img class=\"banner\" src=\"some_ad.png\" alt=\"\" \/> 
} 

내가 JSON 키 'HTML'내부 샘플 HTML 코드를 추가하고 사용했다 '\'이스케이프 문자로 큰 따옴표 (")를 무시.

+0

하지만 HTML 메신저 점점 편집했다 문자열에서 줄에서 내 코드에서 볼 수 있습니다. –

+0

다음과 같이 백틱을 사용할 수 있습니다 : { "html": 자바 문자열 변수 값이 여기에옵니다. } –

+0

기본적으로 URL에 변수 데이터를 게시하고 싶습니다. –