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

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

问题描述

我想用解析数据库开发Web应用程序,因为数据将上传从桌面PC和相同retreival将在解析的移动应用程序来完成。

是否有可能使用解析数据库,网站后台?

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

任何人都可以请帮我,提供一些想法如何做到这一点?

在此先感谢。

解决方案

 是否有可能使用解析数据库对网站的后台?
 

是的,这是可能的: .NET指南,的 REST API

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

是的,你可以使用同一个数据库,应用程序和桌面版本。


对于采用Android创建这样的对象存储数据:

 的parseObject gameScore =新的parseObject(GameScore);
gameScore.put(分数,1337);
gameScore.put(playerName,肖恩普洛特);
gameScore.put(cheatMode,假);
gameScore.saveInBackground();
 

以上code在parse.com创建表(当使用对象存储数据的数据库会自动创建。)检查仪表板:就像下图

对于获取数据试试这个方法:

  ParseQuery查询=新ParseQuery(GameScore);
query.getInBackground(xWMyZ4YEGZ,新GetCallback(){
  公共无效做(的parseObject对象,ParseException的E){
    如果(E == NULL){
      //对象将是你的场均得分
    } 其他 {
      // 出了些问题
    }
  }
});
 

您可以使用WEB应用同样的方法,以及桌面应用程序( REST API


作为创建表的用户,我必须创建这样的对象:

 的parseObject gameScore =新的parseObject(用户);
    gameScore.put(名,dhaval);
    gameScore.put(姓氏,Sodha);
    gameScore.put(电子邮件,xyz@gmail.com);
    gameScore.put(手机,9876543210);
    gameScore.put(地址,XYZ);
    gameScore.put(城市,艾哈迈达巴德);
    gameScore.put(国家,印度);
    gameScore.saveInBackground();
 

以上的对象会创建表的字段( ID,姓,名,电子邮件,电话,地址,城市,...的时间,创造...等


编辑:


得到这样的数据( SELECT * FROM用户WHERE市='AHMEDABAD'和国家='印度'

  ParseQuery lotsOfWins =新ParseQuery(用户);
            lotsOfWins.whereEqualTo(城市,艾哈迈达巴德);

            ParseQuery fewWins =新ParseQuery(用户);
            fewWins.whereEqualTo(国家,印度);

            名单< ParseQuery>查询=新的ArrayList< ParseQuery>();
            queries.add(lotsOfWins);
            queries.add(fewWins);

            ParseQuery mainQuery = ParseQuery.or(查询);
            mainQuery.findInBackground(新FindCallback(){
            公共无效完成(名单<的parseObject> scoreList,ParseException的E){
                如果(E == NULL){
                    Log.d(分数,检索+ scoreList.size()+得分);
                    //此处SIZE为0,则没有内容!
                } 其他 {
                    Log.d(分,错误:+ e.getMessage());
                }
            }
 


下面:公共无效完成(名单<的parseObject> scoreList,ParseException的E)你造成的对象

名单,其中,的parseObject> :是的目的是通过查询返回列表

ParseException的:是异常,如果发生。

因此​​, scoreList.size()给你所查询的所有对象返回总大小。

如何获取数据:

 字符串username = scoreList.getString(用户名);
 


如何保存文件:(无论MIME类型像PNG,JPG,DOC,TXT ....等)的作品,均

使用下面code上传文件:

  ByteArrayOutputStream流=新ByteArrayOutputStream();
                USERIMAGE.com preSS(Bitmap.Com pressFormat.PNG,100,流);
                字节[]的字节数组= stream.toByteArray();
                字符串UsetPhoto =用户+ System.currentTimeMillis的()+形象;
                ParseFile文件=新ParseFile(UsetPhoto,字节);

                的parseObject gameScore =新的parseObject(的UserDetails);
                gameScore.put(userName的,+ userName.getText()的toString());
                gameScore.put(userPhoto,+文件);
                gameScore.saveInBackground();
 

使用上述目的,从解析API retrive文件:

  ParseFile applicantResume =(ParseFile)gameScore.get(userPhoto);
            applicantResume.getDataInBackground(新GetDataCallback(){
              公共无效完成(byte []的数据,ParseException的E){
                如果(E == NULL){
                  //数据具有字节用于恢复
                } 其他 {
                  // 出了些问题
                }
              }
            });
 

在这里,你会得到:公共无效完成(byte []的数据,ParseException的E)

字节[] 字节[] 的文件(不论文件类型 - 如果你上传的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数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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