C++ aide
Fermé
amine69500
Messages postés
418
Date d'inscription
lundi 8 juin 2009
Statut
Membre
Dernière intervention
25 août 2013
-
1 oct. 2012 à 15:57
amine69500 Messages postés 418 Date d'inscription lundi 8 juin 2009 Statut Membre Dernière intervention 25 août 2013 - 3 oct. 2012 à 16:29
amine69500 Messages postés 418 Date d'inscription lundi 8 juin 2009 Statut Membre Dernière intervention 25 août 2013 - 3 oct. 2012 à 16:29
2 réponses
crackman2
Messages postés
1380
Date d'inscription
mercredi 21 septembre 2011
Statut
Membre
Dernière intervention
3 septembre 2015
191
1 oct. 2012 à 16:04
1 oct. 2012 à 16:04
salut vas sur ce lien cela t aideras bcp si tu es débutant:
https://www.codeproject.com/Articles/20027/JSON-Spirit-A-C-JSON-Parser-Generator-Implemented
https://www.codeproject.com/Articles/20027/JSON-Spirit-A-C-JSON-Parser-Generator-Implemented
amine69500
Messages postés
418
Date d'inscription
lundi 8 juin 2009
Statut
Membre
Dernière intervention
25 août 2013
12
2 oct. 2012 à 13:13
2 oct. 2012 à 13:13
Ok super merci
Cordialement
Cordialement
3 oct. 2012 à 16:29
voila j'ai trouvé une fonction qui me permet de parser une chaine de caractere, mais tu peu me dire stp quel est la variable qui prend en compte le text a parser, comme ca je rentre ca valeur.
la fonction
#include <boost/spirit.hpp>
#include <fstream>
#include <sstream>
#include <iostream>
struct json_grammar
: public boost::spirit::grammar<json_grammar>
{
template <typename Scanner>
struct definition
{
boost::spirit::rule<Scanner> object, member, string, value, number, array;
definition(const json_grammar &self)
{
using namespace boost::spirit;
object = "{" >> member >> *("," >> member) >> "}";
member = string >> ":" >> value;
string = "\"" >> *~ch_p("\"") >> "\"";
value = string | number | object | array | "true" | "false" | "null";
number = real_p;
array = "[" >> value >> *("," >> value) >> "]";
}
const boost::spirit::rule<Scanner> &start()
{
return object;
}
};
};
int main(int argc, char *argv[])
{
std::ifstream fs(argv[1]);
std::ostringstream ss;
ss << fs.rdbuf();
std::string data = ss.str();
json_grammar g;
boost::spirit::parse_info<> pi = boost::spirit::parse(data.c_str(), g, boost::spirit::space_p);
if (pi.hit)
{
if (pi.full)
std::cout << "parsing all data successfully" << std::endl;
else
std::cout << "parsing data partially" << std::endl;
std::cout << pi.length << " characters parsed" << std::endl;
}
else
std::cout << "parsing failed; stopped at '" << pi.stop << "'" << std::endl;
}
je lé trouvé ici :
https://theboostcpplibraries.com/boost.spirit
c'est dans GRAMMAR le 2 eme code
Merci de ton aide
Cordialement