• Skip to content
  • Skip to link menu
KDE API Documentation - JsonParser.qml Source File (GCompris-qt)
  • KDE Home
  • Contact Us
 

GCompris-qt

  • src
  • core
JsonParser.qml
1 /* GCompris - JsonParser.qml
2  *
3  * Copyright (C) 2014 Holger Kaelberer <holger.k@elberer.de>
4  *
5  * Authors:
6  * Holger Kaelberer <holger.k@elberer.de>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 import QtQuick 2.0
23 import GCompris 1.0
24 
31 QtObject {
32  id: jsonparser
33 
38  property File jsonFile: File {
39  id: jsonfile
40  name: ""
41 
42  onError: jsonparser.error(msg);
43  }
44 
50  signal error(string msg);
51 
52  /* public interface: */
53 
67  function parseString(json, validateFunc)
68  {
69  var doc;
70  try {
71  doc = JSON.parse(json);
72  // validate if requested:
73  if (validateFunc !== undefined
74  && !validateFunc(doc)) {
75  error("JsonParser: JSON is semantically invalid");
76  return null;
77  }
78  } catch(e) {
79  error("JsonParser: JSON is syntactically invalid: " + e);
80  return null;
81  }
82  return doc;
83  }
84 
94  function parseFromUrl(url, validateFunc)
95  {
96  var json = "'";
97  if (url.substring(0,3) == "qrc" || url.substring(0,4) == "file"
98  || url.substring(0,1) == ":") {
99  json = jsonFile.read(url);
100  if (json != "")
101  return parseString(json, validateFunc);
102  } else if (url.substring(0,4) == "http")
103  error("http:// scheme not yet implemented");
104  else // unknown url scheme
105  error("Unknown url scheme in url parameter");
106  return null;
107  }
108 }
File::error
void error(const QString &msg)
Emitted when an error occurs.
QtQuick
GCompris
File
A helper component for accessing local files from QML.
Definition: File.h:34
This file is part of the KDE documentation.
Documentation copyright © 1996-2015 The KDE developers.
Generated on Tue Jun 2 2015 21:47:47 by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

GCompris-qt

Skip menu "GCompris-qt"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • File List
  • Modules

Class Picker

Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal