1

Hi all am having trouble in parsing the json which as single quote(') and & inside one string value am getting following error.

com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unterminated object at line 1 column 187 path $[0].productName

Now let me tell what i have tried so far am using gson for parsing json which am getting above error, this is the json am trying to parse

[
   {
      "productName":"PETER'S Cheese & Onion  Slice",
      "ref_Products_Display_Name":"",
      "ref_Products_Description":"",
      "ref_Product_Brand_Id":"",
      "ref_Category_Id":"NFz3N19vVGaGh1Uhxx8V",
      "ref_Sub_Category_Id":"5TLxySL5qWWSQh3C0BFV"
   }
] 

Code am trying to parse:

var args: String = call.argument("data")!!
val gson = GsonBuilder().setPrettyPrinting().disableHtmlEscaping() .create()
args = args.replace("\\\"", "'");

args.replace("'","");
val productList = gson.fromJson<ArrayList<OrderDetail>>(args.substring(1, args.length - 1), 
object : TypeToken<ArrayList<OrderDetail>>() {}.type)

OrderDetailModel

public  class  OrderDetail{
    String productName;
    String ref_Products_Display_Name;
    String ref_Products_Description;
    String ref_Product_Brand_Id;
    String ref_Category_Id;
    String ref_Sub_Category_Id;
}
                

Can someone let me know how to parse the above json and thanks in advance!!!

M.Yogeshwaran
  • 1,419
  • 4
  • 22
  • 48
  • Does this answer your question? [How to parse JSON in Java](https://stackoverflow.com/questions/2591098/how-to-parse-json-in-java) – Aaron Morefield May 25 '21 at 17:35
  • no @AaronMorefield i can parse the data but productname which as single quote i cannot do that how to resolve it – M.Yogeshwaran May 25 '21 at 17:38
  • The JSON is legit and can be parsed/deserialized easily and there is nothing wrong with `'` and `&` in strings. I see text replace (never do it for this), so I guess the JSON you provided is not the JSON you have issues with. – terrorrussia-keeps-killing May 25 '21 at 19:44

0 Answers0