I have an array of classes of this type:
public class IndexVO {
public int myIndex;
public String result;
}
And this is my array:
IndexVo[] myArray = { indexvo1, indexvo2 };
I want to convert this array to json, any idea how?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This wouldn’t be as easy as
JSONArray mJSONArray = new JSONArray(Arrays.asList(myArray))since your array contains objects of unsupported class. Hence you will have to make a little more effort:And add
toJSON()method to yourIndexVoclass:However, if you need to generate JSON for more than one class, then consider libraries which do it automatically, flexjson, for example.