9 Replies Latest reply on May 18, 2016 8:32 AM by meghan RSS
    pagrawal-2 Apprentice

    How to access the JSON data passing from external Java Code Via REST Call To TWX Service

    I have written this code Snippet in Java:


    public static void callTW(JSONObject obj) throws Exception {

      String statusMsg = "";



      String uri = "http://localhost:8080/Thingworx/Things/test2/Services/JSON_Split?userid=Administrator&password=admin";

      HttpURLConnection conn = (HttpURLConnection) new URL(uri).openConnection();



      conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");

      OutputStream os = conn.getOutputStream();


      JSONObject obj2=new JSONObject();

      obj2.put("IDA2A2", "6278");

      obj2.put("Number_P", "W10320887");

      obj2.put("Name", "test");


      JSONObject obj3=new JSONObject();

      obj3.put("IDA2A2", "6278");

      obj3.put("Number_P", "W10320887");

      obj3.put("View_P", "Engineering");


      obj.put("partmaster", obj2);

      obj.put("part", obj3);





      if (conn.getResponseCode() != HttpURLConnection.HTTP_OK)


      statusMsg = conn.getResponseCode() + " " + conn.getResponseMessage();

      throw new RuntimeException("Failed : HTTP error code : " + statusMsg);





      catch (Exception e)


      throw new Exception(statusMsg + "." + e);





    This Code actually contains three JSON Object and here I am actually merging two JSON Object into one Object i.e. "obj".

    And Now I want to catch this whole JSON at ThingWorx Side by creating a Service.

    I actually want to split this JSON Object "obj" into its Child object and then store the values in these child objects at TWX Side.

    I hope you guys are getting me.

    What script I should write at TWX Side to catch all this data.