6

betfair交換Webサービスを使用して現在のスポーツ市場のレートを表示するac#windowsアプリを作成しています。

getmarketpricescompressed()

次のような価格文字列を返すメソッド:

106093239~GBP~ACTIVE~0~1~~true~5.0~1343114432333~~N:7337~1~6992.56~2.16~~~false~~~~|2.16~1036.19~L~1~2.14~97.18~L~2~2.12~5.0~L~3~|2.18~467.36~B~1~2.2~34.12~B~2~2.22~162.03~B~3~:414464~2~102181.96~1.86~~~false~~~~|1.85~2900.33~L~1~1.84~1831.59~L~2~1.83~1593.73~L~3~|1.86~58.83~B~1~1.87~1171.77~B~2~1.88~169.15~B~3~

この文字列を適切に解凍する方法がわかりません。今のところ、次のコードを使用しています。

GetMarketPricesCompressedReq price_req1 = new GetMarketPricesCompressedReq();
            price_req1.header = header2;
            price_req1.marketId = marketid_temp;
            price_req1.currencyCode = "GBP";
            GetMarketPricesCompressedResp price_resp = new GetMarketPricesCompressedResp();
            price_resp = bfg2.getMarketPricesCompressed(price_req1);
            //MessageBox.Show(price_resp.errorCode.ToString());
            //richTextBox1.Text = "";
            //richTextBox1.Text = price_resp.marketPrices;
            string prices = price_resp.marketPrices;
            richTextBox1.Text = price_resp.marketPrices;
            string[] ab1 = prices.Split('|');
            string[] temp = ab1[1].Split('~');
            textBox3.Text = temp[0];
            textBox4.Text = temp[4];
            textBox5.Text = temp[8];
            temp = ab1[2].Split('~');
            textBox6.Text = temp[0];
            textBox7.Text = temp[4];
            textBox8.Text = temp[8];
            temp = ab1[3].Split('~');
            textBox9.Text = temp[0];
            textBox10.Text = temp[4];
            textBox11.Text = temp[8];
            temp = ab1[4].Split('~');
            textBox12.Text = temp[0];
            textBox13.Text = temp[4];
            textBox14.Text = temp[8];
            if (ab1.Length >5)
            {
                temp = ab1[5].Split('~');
                textBox15.Text = temp[0];
                textBox16.Text = temp[4];
                textBox17.Text = temp[8];
                temp = ab1[6].Split('~');
                textBox18.Text = temp[0];
                textBox19.Text = temp[4];
                textBox20.Text = temp[8];
            }

いくつかの一致で正常に動作しますが、他のいくつかの一致で文字列の変更を観察したため、例外が生成されます。any1は、この文字列を解凍するための適切なコードを教えてくれますか?グーグルで検索してvbコードを見つけました。あまり役に立ちませんでした、

ところで、私は次のようなものにデータを配置したいと思います:

ここに画像の説明を入力してください

4

3 に答える 3

3

次の点を考慮してください。

a|b|c|d

これには、4 つのチャンクがあります。しかし、必ずしも 4 つだけである必要はありません。2つになることもあれば、6つになることもあります。

の結果として得られる文字列配列を反復して、それを試してみてください

string[] ab1 = prices.Split('|');

何かのようなもの

foreach(var stringChunk in ab1)
{
    string[] temp = stringChunk.Split('~');
    // use the strings here as you please
}

静的テキストボックスの代わりに行ベースの繰り返しコントロールを使用して、データを表示する際にもより動的なアプローチを使用することを検討してください。=)

圧縮データの完全なドキュメントは、https ://docs.developer.betfair.com/betfair/#!page=00008360-MC.00008307-MC で入手できます。

于 2012-07-24T07:34:03.690 に答える
2

推測ですが、データはこのように整理されていると思います

最初に区切られた:|、取得します

106093239~GBP~ACTIVE~0~1~~true~5.0~1343114432333~~N

7337~1~6992.56~2.16~~~偽~~~~
2.16~1036.19~L~1~2.14~97.18~L~2~2.12~5.0~L~3~ 2.18~467.36~B~1~2.2~34.12 ~B~2~2.22~162.03~B~3~

414464~2~102181.96~1.86~~~偽~~~~ 1.85~2900.33~L~1~1.84~1831.59~L~2~1.83~1593.73~L~3~ 1.86~58.83~B~1~1.87~1171.77 ~B~2~1.88~169.15~B~3~

最初の行は明らかにヘッダーで、最初の数字はおそらくマーケット ID だと思います。同様に、後続の各セクションの最初の部分は行識別子です。~のようなもので区切られた

(SelectionId)7337 (Order)1 (TotalMatched?)6992.56 (EvenPoint)2.16 (???)false

~価格行は、このように 4 のタプルで区切られていると思います

(価格)2.16 (MatchAvailable)1036.19 (タイプ)L (注文)1
(価格)2.14 (MatchAvailable)0097.18 (タイプ)L (注文)2
(価格)2.12 (MatchAvailable)0005.00 (タイプ)L (注文)3

例えば。

私の推測をテストするには、Web サイトの BetFair レンダリングと比較する必要があります。

于 2012-07-24T08:02:51.880 に答える
2

vbコードを自分でc#に変換しました。誰かが役に立つと思うかもしれませんが、ここに投稿しています:

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;

namespace stock
{
    class UnpackMarketPricesCompressed : stock.BFExchangeService.MarketPrices
{
        //The substitute code for "\:"
    private const string ColonCode = "&%^@";

    //Unpack the string
    public UnpackMarketPricesCompressed(string MarketPrices)
    {
        string[] Mprices = null;
        string[] Part = null;
        string[] Field = null;
        int n = 0;

        Mprices = MarketPrices.Replace("\\:", ColonCode).Split(':');
        //Split header and runner data
        Field = Mprices[0].Replace("\\~", "-").Split('~');
        //Split market data fields
        marketId = Convert.ToInt32(Field[0]);
        //Assign the market data
        currencyCode = Field[1];
        marketStatus = (stock.BFExchangeService.MarketStatusEnum)Enum.Parse(typeof(stock.BFExchangeService.MarketStatusEnum), Field[2], true);
        delay = Convert.ToInt32(Field[3]);
        numberOfWinners = Convert.ToInt32(Field[4]);
        marketInfo = Field[5].Replace(ColonCode, ":");
        discountAllowed = (Field[6].ToLower() == "true");
        marketBaseRate = float.Parse(Field[7]);
        lastRefresh = long.Parse(Field[8]);
        removedRunners = Field[9].Replace(ColonCode, ":");
        bspMarket = (Field[10] == "Y");

        n = Mprices.Length - 1;
         // ERROR: Not supported in C#: ReDimStatement

        //For each runner
        for (int i = 0; i <= n; i++) 
        {
            Part = Mprices[i + 1].Split('|');
            //Split runner string into 3 parts
            Field = Part[0].Split('~');
            //Split runner data fields
             runnerPrices[i] = new stock.BFExchangeService.RunnerPrices();
            var _with1 = runnerPrices[i];
            //Assign the runner data
            _with1.selectionId = Convert.ToInt32(Field[0]);
            _with1.sortOrder = Convert.ToInt32(Field[1]);
            _with1.totalAmountMatched = Convert.ToDouble(Field[2]);
            _with1.lastPriceMatched = Convert.ToDouble(Field[3]);
            _with1.handicap = Convert.ToDouble(Field[4]);
            _with1.reductionFactor = Convert.ToDouble(Field[5]);
            _with1.vacant = (Field[6].ToLower() == "true");
            _with1.farBSP = Convert.ToDouble(Field[7]);
            _with1.nearBSP = Convert.ToDouble(Field[8]);
            _with1.actualBSP = Convert.ToDouble(Field[9]);
            _with1.bestPricesToBack = Prices(Part[1]);
            _with1.bestPricesToLay = Prices(Part[2]);
        }
    }

    private stock.BFExchangeService.Price[] Prices(string PriceString)
    {
        string[] Field = null;
        stock.BFExchangeService.Price[] Price = null;
        int k = 0;
        int m = 0;

        Field = PriceString.Split('~');
        //Split price fields
        m = (Field.Length / 4) - 1;
        //m = number of prices - 1 
         // ERROR: Not supported in C#: ReDimStatement

        for (int i = 0; i <= m; i++) 
        {
            Price[i] = new stock.BFExchangeService.Price();
            var _with2 = Price[i];
            _with2.price = Convert.ToInt32(Field[k + 0]);
            //Assign price data
            _with2.amountAvailable = Convert.ToInt32(Field[k + 1]);
            _with2.betType = (stock.BFExchangeService.BetTypeEnum)Enum.Parse(typeof(stock.BFExchangeService.BetTypeEnum), Field[k + 2], true);
            _with2.depth = Convert.ToInt32(Field[k + 3]);
            k += 4;
        }
        return Price;
        //Return the array of prices
    }

    }
}
于 2012-07-24T10:37:08.140 に答える