is there any plan or consideration for adding jsonarray and jsonobject as a column in “data” table?
thanks.
What stops you from saving JSON array or object data as string? Then in your data classes which Backendless returns to your app, you could then have a getter method which would transform the string value into a JSON arrays or objects.
Perhaps I am missing something, if so, please clarify.
Regards,
Mark
Thanks Mark.
Thank for your reply.
I was thinking of using String but there is limitation (max 500 length) right. And also, I cannot guess the array size which user will add in my application.
For example,
Sale person (parent class) have name, ranks, commission, …, Shops.
Shops (child class) have owner,address,phone …
cannot know which sale person deal how many shops for one day.
person1 > 3shops
person2 > 7shops
person3 > 4shops
if they have to modify their data in the next day, they don’t know the objectIds for shop, then how do I modify?
person2’s shop2 move to person1?
person3’s shop1’s phone change.
I do apologize if my poor english and little experience make you confuse.
can you give me a correct way of using it.
if 500 is not enough, use TEXT, it can fit a lot more text.
I do not understand how your example with SalesPerson and Shops correlates to the JSON question. Is it a new question or there is a correlation?
Let’s assume you use Android (from your username it appears to be the case), if you have a Java class for SalesPerson and another class for Shop, then you can easily maintain different sizes of arrays for each SalesPerson, Backendless handles it just fine.
In fact, the API makes it super simple to load the related shops for each sales person.
Regards,
Mark
Thanks Mark.
TEXT will be ok for me.
Thanks for your immediate reply.
Could you please help me understand why you want to use Json objects and arrays vs. native objects? What problem are you trying to solve by doing that?
I want to reduce query states. if internet connection is very slow (when speed is under 1kb/s situation, sometimes under 20bps), users cannot make call for another query. most of my users will be from Myanmar. we are getting slow connection most of the time. so, I just want them to get data from one query ( user.getPerperty()).
You really do not need to use JSON (or string property) for that. It is possible to retrieve all related data in a single call. Consider the following example:
SalesPerson and Shop classes:
public class SalesPerson
{
public String name;
public List<Shop> shops;
}
public class Shop
{
public String name;
public String streetAddress;
}
Code to store objects in Backendless:
for( int i =0; i < 3; i++ )
{
SalesPerson salesPerson = new SalesPerson();
salesPerson.name = "Bob " + i;
salesPerson.shops = new ArrayList<Shop>();
for( int j = 0; j < 5; j++ )
{
Shop shop = new Shop();
shop.name = salesPerson.name + " shop" + j;
salesPerson.shops.add( shop );
}
Backendless.Data.of( SalesPerson.class ).save( salesPerson );
}
Code to load SalesPerson objects WITH related shops using single call:
BackendlessDataQuery query = new BackendlessDataQuery();
QueryOptions queryOptions = new QueryOptions();
queryOptions.addRelated( "shops" );
query.setQueryOptions( queryOptions );
BackendlessCollection<SalesPerson> salesPeople;
salesPeople = Backendless.Data.of( SalesPerson.class ).find( query );
System.out.println( "received " + salesPeople.getData().size() );
SalesPerson salesPerson = salesPeople.getData().get( 0 );
System.out.println( "sales person first shop " + salesPerson.shops.get( 0 ).name );
Notice the following line:
queryOptions.addRelated( "shops" );
In that code you add the name of the related property which should be pre-initialized when the parent collection is returned. You can add as many related properties as you want.
Hope this helps.
Mark
Thanks a lot Mark.
That’s what I was looking for.
Backendless Great.