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

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

问题描述

我想使用解析数据库来开发网络应用程序,因为数据将从桌面PC上传,并在解析移动应用程序时完成相同的操作。



是否可以为网站后端使用解析数据库?



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



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



提前感谢。

解决方案

 是否可以使用网站后端的解析数据库? 

是,可以:)






for create table用户必须像下面这样创建对象:

  ParseObject gameScore = new ParseObject ); 
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,ahmedab​​ad);
gameScore.put(Country,India);
gameScore.saveInBackground();

对象ll创建包含字段( ID,名字,姓氏,电子邮件,电话,地址,城市,...时间,创建...等)






EDITED:






获取数据类似( SELECT * FROM USER WHERE CITY = AHMEDABAD'和COUNTRY ='INDIA'

  ParseQuery lotOfWins = new ParseQuery(User) ; 
lotOfWins.whereEqualTo(city,Ahmedab​​ad);

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);
//这里的大小是0,然后是No Data Found!
} else {
Log。 d(score,Error:+ e.getMessage());
}
}






这里: public void done(List< ParseObject> scoreList,ParseException e)对象



列表 :是通过查询返回的对象列表。



ParseException :如果发生则为异常。



> scoreList.size()给出Query返回的所有对象的总大小。



如何获取数据:

  String username = scoreList.getString(username); 






如何保存文件:类型为png,jpg,doc,txt ....等)



使用下面的代码上传文件:

  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();

使用上述对象从parse API中检索文件

  ParseFile applicantResume =(ParseFile)gameScore.get(userPhoto); 
applicantResume.getDataInBackground(new GetDataCallback(){
public void done(byte [] data,ParseException e){
if(e == null){
// data has恢复的字节
} else {
//出错了
}
}
});

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



byte [] byte [] 文件(无论文件类型 - 如果您已经上传了png,然后将该字节另存为png)。



ParseException :is Exception if occur ..


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天全站免登陆