I have been manually entering data's into Firebase DB and if the string i entered contains spaces, i am getting
JsonExceptionorg.json.JSONException: Unterminated object at character
After searching through some Stackoverflow questions, i also added String.valueOf(obj.getString("key"))
; to my coding. But it doesn't work for me.
How to add String with spaces in value field in Firebase. Any suggestions would greatly help my learning.
My code
rootRef.addValueEventListener(new com.firebase.client.ValueEventListener() {
@Override
public void onDataChange(com.firebase.client.DataSnapshot dataSnapshot) {
String Jsondatas=String.valueOf(dataSnapshot.getValue());
try {
JSONObject jsonobj=new JSONObject(Jsondatas);
JSONArray gkArray = jsonobj.getJSONArray("GK");
for(int i=0;i<gkArray.length();i++){
JSONObject obj_gk = gkArray.getJSONObject(i);
String quest = String.valueOf(obj_gk.getString("Question1"));
System.out.println("Questiofrom fb"+quest);
String opt_one = String.valueOf(obj_gk.getString("option1"));
String opt_two = String.valueOf(obj_gk.getString("option2"));
String opt_three = String.valueOf(obj_gk.getString("option3"));
String opt_four = String.valueOf(obj_gk.getString("option4"));
String ans= String.valueOf(obj_gk.getString("answer"));
question.add(quest);
Option1.add(opt_one);
Option2.add(opt_two);
Option3.add(opt_three);
Option4.add(opt_four);
CorrectAns.add(ans);