거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Facebook에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
라이브러리

JSON Parser - MetaTrader 4용 라이브러리

조회수:
42787
평가:
(40)
게시됨:
2014.02.24 06:27
업데이트됨:
2016.11.22 07:32
\MQL4\Include\
json.mqh (23.93 KB) 조회
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

Author:

Andrew Lord

This parses mql4 strings that contain JSON code. It creates a JSONValue that can be used to retrieve the fields within the JSON structure. It also provides a JSONIterator class to loop over object keys.

It parses the JSON using a simple a recursive descent parser. It requires the Hash class.

I still have to implement the parsing of unicode escaped characters.

The Codebase version might not be the most recent. The latest version can be found here.

Documentation:

JSONParser class

JSONValue class


Example:

#include "hash.mqh"
#include "json.mqh"
    
string s = "{ \"firstName\": \"John\", \"lastName\": \"Smith\", \"age\": 25, "+
"\"address\": { \"streetAddress\": \"21 2nd Street\", \"city\": \"New York\", \"state\": \"NY\", \"postalCode\": \"10021\" },"+
" \"phoneNumber\": [ { \"type\": \"home\", \"number\": \"212 555-1234\" }, { \"type\": \"fax\", \"number\": \"646 555-4567\" } ],"+
" \"gender\":{ \"type\":\"male\" }  }";

    JSONParser *parser = new JSONParser();

    JSONValue *jv = parser.parse(s);

    if (jv == NULL) {
        Print("error:"+(string)parser.getErrorCode()+parser.getErrorMessage());
    } else {


        Print("PARSED:"+jv.toString());
        
        if (jv.isObject()) { // check root value is an object. (it can be an array)

            JSONObject *jo = jv;

            // Direct access - will throw null pointer if wrong getter used.
            Print("firstName:" + jo.getString("firstName"));
            Print("city:" + jo.getObject("address").getString("city"));
            Print("phone:" + jo.getArray("phoneNumber").getObject(0).getString("number"));

            // Safe access in case JSON data is missing or different.
            if (jo.getString("firstName",s) ) Print("firstName = "+s);

            // Loop over object keys
            JSONIterator *it = new JSONIterator(jo);
            for( ; it.hasNext() ; it.next()) {
                Print("loop:"+it.key()+" = "+it.val().toString());
            }
            delete it;
        }
        delete jv;
    }
    delete parser;
The latest version can also be found here.
SwingCyborg SwingCyborg

This Expert Advisor is based on your human ability to predict medium and long term trends.

MACD vs Signal line MACD vs Signal line

It opens and close transactions depends on MACD vs signal line - upper - opens buy, closes sell, below - closes buy, opens sell.

Universal EA Universal EA

This is my first Expert Advisor so please give feedback on how I can improve it to make the best possible EA. Thanks for the inputs in advance and happy trading.

Condition Scanner Condition Scanner

Scan for conditions in which you have an interest. Show where the condition arose historically on the current Symbol and timeframe. On a separate panel, show where the condition has currently arisen for any of your chosen symbols and timeframes.