-2

I know there are many topics about this subject but I think all of them have got old because all of them have been written something like this: JSONArray jsonArray = new JSONArray(String variable); .

Now JSONArray's constructor gets just int value as capacity or gets nothing.

So with this new JSONArray method how can I convert String to JsonArray? This is my String: ["https://serverv2.nokhbgan.ir/api/Products/DownloadFileV1?src=NGrvxefUHed_1.png","https://serverv2.nokhbgan.ir/api/Products/DownloadFileV1?src=NGrvxefUHed_2.png"]

2
  • who told you that there is no constructor with String as input? Commented May 18, 2021 at 5:18
  • @dinkar_kumar I tried that, when I put a string as a parameter to the method, android studio draw a red line under my code and told me Required type : int Provided: String Commented May 18, 2021 at 5:21

1 Answer 1

0

JSONArray and JsonArray are two different class one from package org.json; and other from package com.google.gson;

JSONArray Do have the constructor which takes a string as input on the other hand JsonArray from google's Gson library don't.

I think you are suppose to use JSONArray but mistakenly imported JsonArray because you might be using gson library for some json parsing.

Note: Always make sure to double confirm the import to see what class you are using because many time they have exact same name, at least in this case the alphabets cases were different, but you can find the classes to be having exact same name and everything so please confirm whether you are using a correct intended class or not, this may be use cause of time waste many times.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.