Android Firebase Data Retrieving map correctly without no spacing between words

Published

I need to retrieve data (two words – Mega building) from Firebase correctly. However,
"Mega building" is retrieved as "Megabuilding". As seen, it happens without space between two words. Is there any solution for this to draw data like "Mega building"? or Can it be done without space, is there an alternative solution when retrieving JSON object data?

Firebase node:

My node;
Pro_:
     Basket:
        ID_1:
           cat: “ Titan Tech”
           info:”Mega Building” 
           orderid:”Ref_1” 
        ID_2:
           cat: “Tech”
           info:”Android” 
           orderid:”Ref_2” 
     name:”Mike”

My function:

Intent intent=this.getIntent();
Bundle bundle=intent.getExtras();
Map<String, Object> map1 = (Map)bundle.getSerializable(“basket”);

//First output
System.out.println(“My_basket:”+map1.values());

for (Object value : map1.values()) {
    JSONObject json = null;
    try {
        json = new JSONObject(String.valueOf(value).replaceAll(" ",""));
        String cat_ = json.getString(“cat”);
        String info_ = json.getString(“info”);
        String orderid_ = json.getString(“orderid”);

    //Second output
        System.out.println(“Info_:”+info_);

    } catch (JSONException e) {
//Third output
        e.printStackTrace();
    }
}

First output:

My_basket:[{cat=Titan Tech, info=Mega Building, orderid=Ref_1,}, {cat=Tech, info=Android, orderid=Ref_2,}]

Second output (ı want to retrieve like “Mega Building”. Problem line is here)

Info_: MegaBuilding

Third output

org.json.JSONException: Unterminated object at character 23 of etc

Source: Android Questions

Published
Categorized as android, firebase-realtime-database, google-maps, java, json

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq