title: JSON Header Array in Java
body: <p>I need to POST data in getting IOT results:</p>
  
  <p>Am getting the Error as follows:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.Error: Unresolved compilation
    problems:     JSONObject cannot be resolved to a type     JSONObject cannot
    be resolved to a type
      at IOT.httpPostWithBody.sendJSONData(httpPostWithBody.java:40)  at
    IOT.httpPostWithBody.main(httpPostWithBody.java:27)</p>
  </blockquote>
  
  <p>My JAVA Program As Follows:</p>
  
  <pre><code>package IOT;
  
  //package com.test.Second;
  
  import java.util.HashMap;
  import java.util.Map;
  import org.apache.http.HttpResponse;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.entity.StringEntity;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.message.BasicHeader;
  import org.apache.http.protocol.HTTP;
  import org.json.JSONObject;
  
  
  public class httpPostWithBody {
  
  public static void main(String args[]) {
      String Message = "6f2159f998";
  
      try {
          new httpPostWithBody().sendJSONData(Message);
      } catch (Exception E) {
  System.out.println("Exception Occured. " + E.getMessage());
      }
      }
  
  public String sendJSONData(String message) throws Exception {
  
      //creating map object to create JSON object from it
  Map&lt; String, Object &gt;jsonValues = new HashMap&lt; String, Object &gt;();
  jsonValues.put("thing_key",message);
  jsonValues.put("from", "2016/08/29 16:55:00");
  jsonValues.put("to", "2016/08/29 17:05:00");
  jsonValues.put("time_zone", "Asia/Calcutta");
  jsonValues.put("per", "200");
  jsonValues.put("metrics", "1st data");
  
  JSONObject json = new JSONObject(jsonValues);
  
  
  String url = "https://api.datonis.io/api/v3/datonis_query/thing_data";
  DefaultHttpClient client = new DefaultHttpClient();
  HttpPost post = new HttpPost(url);
  post.setHeader("Content-Type", "application/json");
  post.setHeader("X-Auth-Token", "TtJd3Qb9eq5xqPfK2zabXg");
  //setting json object to post request.
  StringEntity entity = new StringEntity(json.toString(), "UTF8");
  entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
  post.setEntity(entity);
  //this is your response:
  HttpResponse response = client.execute(post);
  System.out.println("Response: " + response.getStatusLine());
      return response.getStatusLine().toString();
  }
  }
  </code></pre>