0

I know exactly what the problem is. My attempts to solve it have been futile.

Here's the problem in the json input:

Json

As you can see, the item option_value is sometimes an array and sometimes it's just a simple string. My parser however, treats it as an array because that's how I've defined it:

....
public class Options
    {
        String product_option_id;
        String option_id;
        String name;
        String type;
        String required;
        List<OptionValue> option_value;
....

....
public class OptionValue
        {
            String product_option_value_id;
            String option_value_id;
            String name;
            String image;
            String price;
            String price_prefix;
....

How do I modify my class so that it is able to check if option_value is an array or simply a string and is treated as such?

Asim
  • 6,962
  • 8
  • 38
  • 61
  • Might be changes requires into JSON data, add one parameter isOption into your json and set true if option_value is a JsonArray, else set isOption false for option_value is a empty string. Also made changes into your code according isOption value. – Karan Maru Feb 04 '15 at 07:36
  • Making changes in the json is not an option I'm afraid. – Asim Feb 04 '15 at 07:41
  • one possible solution : instead of empty string the default value of option_value would be null & it would be useful to check wheater its Json Array or not. – Karan Maru Feb 04 '15 at 09:05
  • quick fix: try to get array in try and if exception comes then get string in catch. you can also get string in finally. :) – Umer Feb 05 '15 at 04:26

0 Answers0