????GET???????JSON??????£?
{
"data":
[
{
"id": 0??
"name": "A"??
"score": 100
}??
{
"id": 1??
"name": "B"??
"score": 200
}
]
}
?????????id?????????????????????????????????洦?????????????
????POST????JSON??????£?
????{
????"id": 0??
????"name": "C"??
????"score": 300
????}
??????????????????????index???????
????def index():
????cur = g.db.execute('select id?? name?? score from rank order by score desc;')
????result = cur.fetchmany(100)
????data = []
????for row in result:
????data.append({'id': row[0]?? 'name': row[1]?? 'score': row[2]})
????return jsonify({'data': data})
??????????jsonify??g??flask?????????治?????????????????????flask??????
???????????????????????????????????100?????????????curl??????????????????????create??????
????def create():
????status = {'status': 'OK'}
????if not request.json or not 'name' in request.json or not 'score' in request.json:
????status['status'] = 'bad request'
????try:
????g.db.execute('insert into rank (name?? score) values (??? ?)'?? [request.json['name']?? request.json['score']])
????g.db.commit()
????except:
????status['status'] = 'database error'
????return jsonify(status)
?????????POST??????JSON?????????????request.json??????????args????form???????????????status??????????????????
????????curl???????POST????Σ????????POST?????м????????
????curl -i -X POST -H "Content-Type: application/json" -d '{"id": 0?? "name": "xyz"?? "score": "800"}' 127.0.0.1:5000/scores
????-H???????????????????-d????????Я???????????????????????????????JSON?????
??????????????????????????????????дC#????????
?????????????????????????????????????????UI?????
?????????????????????????????MonoBehaviour?????????????????????Coroutine????????????????????????Unity?????????????з??????????????????????????????£?
private static SaveLoad _instance = null;
public static SaveLoad Instance {
get
{
if (_instance == null)
{
GameObject go = new GameObject("SaveLoadGameObject");
DontDestroyOnLoad(go);
_instance = go.AddComponent<SaveLoad>();
}
return _instance;
}
}