Working with StringBuilder came across a problem. I need to put a StringBuilder in JSONArray, but when i did my string is shuffled. How can I fix this?
My line before:
[{"id":"iprod","name":"soup","categoryId":"categoryId123","categoryName":"soup","imageUrl":"c/image","price":5.0,"weight":123.0,"ingredients":["chicken","rice"],"nutrition":{"energy":{"kilojoules":123,"kilocalories":123},"fat":123,"carbohydrate":123,"protein":123},"currency":"123"}]
My line after:
[{"nutrition":{"protein":123,"fat":123,"carbohydrate":123,"energy":{"kilojoules":123,"kilocalories":123}},"price":5,"imageUrl":"c/image","name":"soup","weight":123,"ingredients":["chicken","rice"],"currency":"123","id":"iprod","categoryName":"soup","categoryId":"categoryId123"}]
Code:
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
br.close();
System.out.println(sb.toString());
JSONArray responseObject = new JSONArray(sb.toString());
System.out.println(responseObject.get(0));