如何将数据从网站存储到 parse.com 以及如何在我的应用程序中获取它的数据 [英] How to store data from website to parse.com And how to to fetch data of it in my application

查看:22
本文介绍了如何将数据从网站存储到 parse.com 以及如何在我的应用程序中获取它的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 parse 数据库来开发 Web 应用程序,因为数据将从台式机上传,并在 parse 移动应用程序中完成相同的检索.

是否可以将解析数据库用于网站后端?

因为我想为应用程序和桌面版本使用相同的解析数据库.

任何人都可以通过提供一些想法来帮助我吗?

提前致谢.

解决方案

是否可以将解析数据库用于网站后端?

是的,有可能:)

<小时>

对于创建表用户,我必须创建如下对象:

ParseObject gameScore = new ParseObject("User");gameScore.put("名字", "dhaval");gameScore.put("Last Name", "Sodha");gameScore.put("Email", "xyz@gmail.com");gameScore.put("电话", "9876543210");gameScore.put("地址", "xyz");gameScore.put("城市", "艾哈迈达巴德");gameScore.put("国家", "印度");gameScore.saveInBackground();

上面的对象将创建包含字段的表(ID、名字、姓氏、电子邮件、电话、地址、城市、...时间、创建...等)

<小时>

<小时>

获取数据如 (SELECT * FROM USER WHERE CITY = 'AHMEDABAD' and COUNTRY = 'INDIA')

 ParseQuery lotOfWins = new ParseQuery("User");lotOfWins.whereEqualTo("city", "艾哈迈达巴德");ParseQuery littleWins = new ParseQuery("User");几个Wins.whereEqualTo(国家",印度");列表查询 = 新的 ArrayList();query.add(lotsOfWins);query.add(fewWins);ParseQuery mainQuery = ParseQuery.or(queries);mainQuery.findInBackground(new FindCallback() {public void done(List scoreList, ParseException e) {如果(e == null){Log.d("score", "Retrieved" + scoreList.size() + "scores");//HERE SIZE 为 0 然后未找到数据!"} 别的 {Log.d("score", "错误:" + e.getMessage());}}

<小时>

这里:public void done(List scoreList, ParseException e) 你在对象中得到结果

List:查询返回的对象列表.

ParseException:如果发生是异常..

因此,scoreList.size() 为您提供查询返回的所有对象的总大小.

如何获取数据:

String username = scoreList.getString("username");

<小时>

如何保存文件:(无论什么 MIME 类型,如 png、jpg、doc、txt...等)它都适用

使用以下代码上传文件:

ByteArrayOutputStream stream = new ByteArrayOutputStream();USERIMAGE.compress(Bitmap.CompressFormat.PNG, 100, 流);byte[] byteArray = stream.toByteArray();String UsetPhoto = "user"+System.currentTimeMillis()+"image";ParseFile 文件 = 新的 ParseFile(UsetPhoto, byteArray);ParseObject gameScore = new ParseObject("UserDetails");gameScore.put("userName", "" + userName.getText().toString());gameScore.put("userPhoto", "" + file);gameScore.saveInBackground();

使用上述对象从解析 API 检索文件:

ParseFile 申请人简历 = (ParseFile)gameScore.get("userPhoto");申请人Resume.getDataInBackground(new GetDataCallback() {公共无效完成(字节 [] 数据,ParseException e){如果(e == null){//数据包含用于简历的字节} 别的 {//出问题了}}});

你得到:public void done(byte[] data, ParseException e)

byte[] : byte[] 文件(无论文件类型 - 如果您上传了 png,则将该字节保存为 png).

ParseException : 如果发生是异常..

I want to use the parse database for developing web app, since data will upload from the desktop PC and retreival of the same will be done in parse mobile application.

Is it possible to use the parse database for website backend ?

Since I want to use same parse database for application and desktop version.

Can anyone please help me, by providing some idea how to achieve that?

Thanks in advance.

解决方案

Is it possible to use the parse database for website backend ?

YES, it is possible: .NET Guide, REST API

Since I want to use same parse database for application and desktop version.

YES, you can use same database for application and desktop version.


for store data using ANDROID create object like:

ParseObject gameScore = new ParseObject("GameScore");
gameScore.put("score", 1337);
gameScore.put("playerName", "Sean Plott");
gameScore.put("cheatMode", false);
gameScore.saveInBackground();

above code is create table in parse.com(database is automatically created when you store data using object.) check dashboard: like below image

for fetch data try this way:

ParseQuery query = new ParseQuery("GameScore");
query.getInBackground("xWMyZ4YEGZ", new GetCallback() {
  public void done(ParseObject object, ParseException e) {
    if (e == null) {
      // object will be your game score
    } else {
      // something went wrong
    }
  }
});

same way you can use for WEB Application as well Desktop application (REST API)


for create table User i have to create object like:

ParseObject gameScore = new ParseObject("User");
    gameScore.put("First Name", "dhaval");
    gameScore.put("Last Name", "Sodha");
    gameScore.put("Email", "xyz@gmail.com");
    gameScore.put("Phone", "9876543210");
    gameScore.put("Address", "xyz");
    gameScore.put("City", "ahmedabad");
    gameScore.put("Country", "India");
    gameScore.saveInBackground();

above Object ll create table with fields(ID ,First Name, Last Name, Email, Phone, Address, City, ... time, created...etc )


EDITED:


get data like (SELECT * FROM USER WHERE CITY = 'AHMEDABAD' and COUNTRY = 'INDIA')

           ParseQuery lotsOfWins = new ParseQuery("User");
            lotsOfWins.whereEqualTo("city", "Ahmedabad");

            ParseQuery fewWins = new ParseQuery("User");
            fewWins.whereEqualTo("country", "India");

            List<ParseQuery> queries = new ArrayList<ParseQuery>();
            queries.add(lotsOfWins);
            queries.add(fewWins);

            ParseQuery mainQuery = ParseQuery.or(queries);
            mainQuery.findInBackground(new FindCallback() {
            public void done(List<ParseObject> scoreList, ParseException e) {
                if (e == null) {
                    Log.d("score", "Retrieved " + scoreList.size() + " scores");
                    // HERE SIZE is 0 then 'No Data Found!'
                } else {
                    Log.d("score", "Error: " + e.getMessage());
                }
            }


Here: public void done(List<ParseObject> scoreList, ParseException e) you get result in object

List<ParseObject>: is list of object return by query.

ParseException: is Exception if occur..

So, scoreList.size() give you Total size of all Object return by Query.

How Fetch data:

String username = scoreList.getString("username");


How Save File: (Whatever MIME type like png,jpg,doc,txt....etc)its works for all

Upload File using Below code:

ByteArrayOutputStream stream = new ByteArrayOutputStream();
                USERIMAGE.compress(Bitmap.CompressFormat.PNG, 100, stream);
                byte[] byteArray = stream.toByteArray();
                String UsetPhoto = "user"+System.currentTimeMillis()+"image";
                ParseFile file = new ParseFile(UsetPhoto, byteArray);

                ParseObject gameScore = new ParseObject("UserDetails");
                gameScore.put("userName", "" + userName.getText().toString());
                gameScore.put("userPhoto", "" + file);
                gameScore.saveInBackground();

retrive file from parse API using above object:

ParseFile applicantResume = (ParseFile)gameScore.get("userPhoto");
            applicantResume.getDataInBackground(new GetDataCallback() {
              public void done(byte[] data, ParseException e) {
                if (e == null) {
                  // data has the bytes for the resume
                } else {
                  // something went wrong
                }
              }
            });

Here you get: public void done(byte[] data, ParseException e)

byte[] : byte[] of file(whatever file type - if you have uploaded png then save that byte as png).

ParseException : is Exception if occur..

这篇关于如何将数据从网站存储到 parse.com 以及如何在我的应用程序中获取它的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆