CSTest/网页请求/Json.h

43 lines
1.3 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include "pub.h"
class Json
{
private:
int type = 0;//1是对象2是数组3是字符串4是数字或布尔或null
std::map<CString, Json> valueMap; //存放json对象
std::map<CString, Json>::iterator CurrIter;
std::vector<Json> valueVector; //存放数组对象
CString value = _T(""); //值
int insertObj(const CString JsonStr, Json& json); //解析对象
int insertArr(const CString JsonStr, Json& json); //解析数组
int insertNum(CString str, Json& json); //解析数字
int GetValue(CString jsonStr, int Begin, CString& value);
public:
~Json();
int parse(CStringA str); //解析数据
int parse(CStringW JsonStr); //解析数据
Json& operator[] (int JsonInt);
Json& operator[] (CStringW JsonStr);
Json& operator[] (CStringA JsonStr);
void operator= (int Json);
void operator= (CStringA JsonStr);
void operator= (CStringW JsonStr);
void operator= (Json JsonInt);
void append(Json Json);
void clear();
void RemoveAt(CStringA Item);
void RemoveAt(CString Item);
void RemoveAt(INT Index);
CStringA asCStringA();
CString asCString();
int asInt();
double asDouble();
UINT Size(); //获取数组或者MAP的个数
std::map<CString, Json>::iterator getBegin();
std::map<CString, Json>::iterator getEnd();
std::map<CString, Json>::iterator Find(CString key);
CStringW writeCString(); //把json对象转换成CString
CStringA write(); //把json对象转换成String
};