0

I have a json file on server:

{"images":[
{"url":"...", "likes":"123"}, 
{"url":"...", "likes":"234"},
{"url":"...", "likes":"345"}
]}

I get the json file on android read it, but if someone likes a picture i want to change the value of the first picture from 123 to 124, is this possible and how can i do this?

The whole point is to change a json value on server,from client side. Also if this isn't possible how can i make this happen?

Also if i want to get the Top50 rated pictures,how can i sort them and get only the 50 picture,without getting all pictures and sorting them on android ?

Which one is better,initializing the Top50 images,when the user starts the app,or when the user click on the button Top50.I assume that if its when he click the button,there might be some performance issues server side?

My other idea is to have a function server side,which every 10 min,executes automatically and gets the Top50 rated and makes something like json file.So it all happens server side automatically.

risto
  • 100
  • 8

3 Answers3

0

To make this happen, client should expose some interface, i.e. function that will allow to modify file on server side. The interface and implementation of this function greatly depends on server itself, i.e. which protocols it handles, what built-in or external modules it supports, which languages are supported, etc... For example, the classic scenario is using apache as HTTP server, CGI enabled, and write CGI function in perl. So, in this case interface would look like http://server.name/like.cgi?image=image123.

pmod
  • 10,450
  • 1
  • 37
  • 50
  • I use serversfree.com,the pictures are uploaded on ftp.I am dont really know what my options are,but this sound reasonable.Thanks! – risto Mar 08 '15 at 09:16
  • @risto According to this http://www.freehostsfinder.com/host-review/hosting_review.php?HostID=597 with free account CGI scripting is not available. But PHP is available. I have no experience with PHP but this maybe helpful http://nitschinger.at/Handling-JSON-like-a-boss-in-PHP http://stackoverflow.com/questions/3921520/writing-json-object-to-json-file-on-server – pmod Mar 09 '15 at 21:28
0

How to modify the values on the server ?

For this every like of a photo should be a post request of this sort.

{
    "data": [
        {
            "image_id": 3133456,
            "likes": 343
        },
        {
            "image_id": 3133456,
            "likes": 343
        }
    ]
}

On parsing this request server updates the corresponding image's like on the server.

How to get the top 50 rated/liked images from the server ?

Again you send a get request to such a url http://server.getsomething.com/getTop50Images

On server side

On receiving such a request you make a query on the table in your database something like this

select image_id , image_url, likes from image_table limit 50 ORDER BY likes ASC

Now getting those query results and returning them as a json would not be a performance hit until you have huge bulk of data. like some million rows may be in your database.

Response can be something like this

{
    "result": [
        {
            "image_id": 3133456,
            "likes": 34400,
            "url": "http://flickr.com/someimage"
        },
        {
            "image_id": 3133456,
            "likes": 34380,
            "url": "http://flickr.com/someimage"
        }
    ]
}
cafebabe1991
  • 4,928
  • 2
  • 34
  • 42
  • So i should be using database>json>android for the whole thing? Like mysql database with image,url,likes,category and json to parse the data to android and the same if i want to parse data from androd to database? – risto Mar 08 '15 at 11:06
  • Yes.. But don't you already have these entities under your control ? – cafebabe1991 Mar 08 '15 at 11:16
  • I just have json file stored on ftp server.And i wish i could avoid using database someway. – risto Mar 08 '15 at 11:25
0

You still avoid using a database yourself but can lease it from clouds services like parse. However if you won't be using those services then you can take a look at ftp packages for js. Like the neo JavaScript library by apache. But still a good choice will be to go with the database approach (is quiet simpler).

cafebabe1991
  • 4,928
  • 2
  • 34
  • 42