0

I have this code from JSONParser.java

 try{
            JSONArray postArray = jsonObject.getJSONArray("posts");
            // Go through each post
            for (int i = 0; i < postArray.length(); i++) {
                JSONObject postObject = postArray.getJSONObject(i);

                Post post = new Post();
post.setCfs(postObject.getJSONObject("custom_fields").optString("entity", "N/A"));

that displays this

["Some text"]

I want it to display without [" and "]

My Json for that specific part is as below

"posts":[{
"date":"2016-02-10 10:28:42",
"categories":[{}],
"tags":[],
"author":{"name":"admin"},
"custom_fields":{
                 "ref_number":["ITB NUMBER: ITB\/002\/2016"],
                 "deadline":["26 February, 2016"],
                 "entity":["Refugees (xxx)"]
                }

1 Answer 1

1

It seems that "entity" is array and you should try something like that:

post.setCfs(postObject.getJSONObject("custom_fields").optJSONArray("entity").getString(0));
Sign up to request clarification or add additional context in comments.

1 Comment

Thx. The code works like a charm, however i have edited and i want to pass the custom fields to the Webview.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.