How to read JSON object file using java and pass it to request
<p>I am using the below code:-</p>
<pre><code>import org.json.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.junit.Assert;
import org.junit.Test;  
import network.Authorization;
import network.ContentType;
import network.HTTPHelper;
import network.HTTPRequest;
import network.HTTPResponse;

import static org.junit.Assert.*;

import java.io.FileReader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public void testSendPOSTRequest() {
    try {
        HTTPRequest request = new HTTPRequest();

        request.url = &quot;https://myURL/api/products&quot;;
        request.contentType = ContentType.JSON;
        Map&lt;String, String&gt; authKeyValue = new HashMap&lt;&gt;();
        authKeyValue.put(Authorization.Type.toString(), &quot;Token token=zkz,email=test7@gmail.com&quot;);
        request.setAuthorization(authKeyValue);

        JSONParser parser = new JSONParser();
        
        try {
 
            Object obj = parser.parse(new FileReader(&quot;./src//productApi&quot;));
 
            JSONObject jsonObject = (JSONObject) obj;
 
            String name = (String) jsonObject.get(&quot;Name&quot;);
            String author = (String) jsonObject.get(&quot;Author&quot;);
            JSONArray companyList = (JSONArray) jsonObject.get(&quot;Company List&quot;);
 
            System.out.println(&quot;Name: &quot; + name);
            System.out.println(&quot;Author: &quot; + author);
            System.out.println(&quot;\nCompany List:&quot;);
            Iterator&lt;String&gt; iterator = companyList.iterator();
            while (iterator.hasNext()) {
                System.out.println(iterator.next());
            }
 
        } catch (Exception e) {
            e.printStackTrace();
        }
    
        
        
        HTTPHelper helper = new HTTPHelper();
        HTTPResponse response = helper.sendPOSTRequest(request);
        
        System.out.println(&quot;POST Success&quot;);
        System.out.println(&quot;Response code: &quot; +response.statusCode.toString());
        System.out.println(&quot;Payload: &quot; +response.payload);
        assertTrue(true);
        
    } catch (Exception e) {
        System.out.println(&quot;&quot;+e.getMessage());
        assertTrue(false);
    } finally {
        System.out.println(&quot;Exist Run&quot;);    
    }
</code></pre>
<p>I am also getting error in below line:-</p>
<pre><code>  Iterator&lt;String&gt; iterator = companyList.iterator();
</code></pre>
<p>Eclipse showing as tips/error as :-</p>
<blockquote>
<p>The method iterator() is undefined for the type JSONArray</p>
<p>Add to cast to</p>
</blockquote>
<p>Can anyone give me a solution of above problem or any alternative way so I can read a JSON object from file and pass it directly to payload as request</p>