2017-12-20 3 views
-1

私はjsonデコード後に得たurlよりもjsonからurlを取得しています.HTMLを取得するには、html bodyが投稿されるべきコンテンツ配列があるという形で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である配列内の文字列ではありません掲示されてページの?

uは私が持っていたすべての時間は(あなたのケースのHTML文字列で)任意の文字列を送信するために

+0

問題は非常に悪い記述されている。説明しようより具体的には、クラップスをカットすることで –

+0

URLの内容の配列にhtmlの本文を投稿する必要があります –

+0

サンプルの入力とサンプル出力を追加してください – Ganeshkumar

答えて

0

すなわちコンテンツ配列に一度で完了し、それを送信するためのURLを打つには、HTMLの行ごとに出力して見ることができるように、あなたはエスケープ文字を使用する必要があります。 '/'はJSONの場合はエスケープ文字です。上記の例では

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

私はJSONのキー「HTML」内のサンプルHTMLコードを追加し、使用している「\」エスケープ文字として二重引用符( ")を無視する。

+0

を編集していましたが、あなたのコードで見ることができるように文字列で入力してください。 –

+0

あなたは '' 'のようにバッククォートを使うことができます: { "html":あなたのjava文字列変数の値はここにあります } –

+0

私は基本的に私はURL変数のデータを投稿したい –

関連する問題