0
procedure TMainForm.btn1Click(Sender: TObject);
var
  lHTTP: TIdHTTP;
begin
  lHTTP := TIdHTTP.Create(nil);
  try
    mmo1.Text := lHTTP.Get('http://guessit.io/guess?filename=House.of.Cards.2013.S02E03.1080p.NF.WEBRip.DD5.1.x264-NTb.mkv');
  finally
    lHTTP.Free;
  end;
end;

the result will be like that:

{
   "series":"House of Cards",
   "episodeNumber":3,
   "releaseGroup":"NTb",
   "format":"WEBRip",
   "season":2,
   "audioCodec":"DolbyDigital",
   "year":2013,
   "mimetype":"video/x-matroska",
   "container":"mkv",
   "videoCodec":"h264",
   "other":[
      "Netflix"
   ],
   "audioChannels":"5.1",
   "screenSize":"1080p",
   "type":"episode"
}

how i can read the series ("series": "House of Cards") value for example.

i try to use

Function ExtractBetweenTags(Const Line, TagI, TagF: string): string;
var
  i, f : integer;
begin
  i := Pos(TagI, Line);
  f := Pos(TagF, Copy(Line, i+length(TagI), MAXINT));
  if (i > 0) and (f > 0) then
    Result:= Copy(Line, i+length(TagI), f-1);
end;

mmo1.Text := StringReplace(ExtractBetweenTags(mmo1.Text,'"series": "','"'), ' ', '-',[rfReplaceAll, rfIgnoreCase]);

but i need to parsing all the values automatically

TLama
  • 75,147
  • 17
  • 214
  • 392
RepeatUntil
  • 2,272
  • 4
  • 32
  • 57
  • Which Delphi version you are using? You are getting information in JSON format and newer versions have JSON parsing out of the box. For older you can use some of existing 3rd party libraries. – Dalija Prasnikar Nov 21 '14 at 09:53
  • @DalijaPrasnikar Delphi XE7 , i don't know if this output called JSON or not. `{"series": "House of Cards", "episodeNumber": 3, "releaseGroup": "NTb", "format": "WEBRip", "season": 2, "audioCodec": "DolbyDigital", "year": 2013, "mimetype": "video/x-matroska", "container": "mkv", "videoCodec": "h264", "other": ["Netflix"], "audioChannels": "5.1", "screenSize": "1080p", "type": "episode"}` – RepeatUntil Nov 21 '14 at 10:14
  • If it JSON, friendly servers will indicate it as the content type header in the HTTP response. You can use a browser plugin like Firebug to see the HTTP headers. (it looks like JSON to me) – mjn Nov 21 '14 at 10:48

3 Answers3

1

You might use DBXJSON contained in Delphi since Delphi 2010, an other option could be to use e.g. SuperObject.
Since your shown example is a simple JSON String without nesting you might access the cointained values by just interating over a TJSONObject acessing as TJSONArray.
This array consists of Pairs of "Name" and the value.
An simple example shown with the string you provided:

uses
DBXJSON;

procedure TForm7.Button1Click(Sender: TObject);
var
  S:String;
  I:Integer;
  JObj:TJSONObject;
  Pair : TJSONPair;
begin
  s := '{"series": "House of Cards", "episodeNumber": 3, "releaseGroup": "NTb", "format": "WEBRip", "season": 2'
        +', "audioCodec": "DolbyDigital", "year": 2013, "mimetype": "video/x-matroska", "container": "mkv", "videoCodec": "h264", "other": ["Netflix"], "audioChannels": 

"5.1", "screenSize": "1080p", "type": "episode"}';
  JObj := TJSONObject.ParseJSONValue(s) as TJSONObject;
  for I := 0 to TJSONArray(JObj).Size - 1 do
    begin
       Pair := TJSONPair(TJSONArray(JObj).Get(i));
       Memo1.Lines.Add( Pair.JsonString.Value + '=' + Pair.JsonValue.ToString)
    end;
end;
bummi
  • 27,123
  • 14
  • 62
  • 101
1

You can parse the object with class like this:

uses System.JSON, Rest.JSON;

type
  TGuess = class(TObject)
  public
    fseries: string;
    fepisodeNumber: integer;
    freleaseGroup: string;
    fformat: string;
    fseason: integer;
    faudioCodec: string;
    fyear: integer;
    fmimetype: string;
    fcontainer: string;
    fvideoCodec: string;
    fother: TArray<string>;
    faudioChannels: string;
    fscreenSize: string;
    ftype: string;
  end;

var
  g: TGuess;
  s: string; // your input string

  // g object will be created by following call and will contain parsed values
  g := TJson.JsonToObject<TGuess>(s); 

  // do something with g

  // release g after it is no longer needed
  g.Free;
Dalija Prasnikar
  • 27,212
  • 44
  • 82
  • 159
0

Thanks for all the answers but here what i finally figure it out

procedure TMainForm.btn1Click(Sender: TObject);
var
  S : String;
  NS , S1,S2,series,season,episodeNumber : String;
  L , I , LN : integer;
  MM :TStringList;
begin
  try
    MM := TStringList.Create;
    NS := '';
    S := '{"series": "House of Cards", "episodeNumber": 3, "releaseGroup": "NTb", "format":'+
    '"WEBRip", "season": 2, "audioCodec": "DolbyDigital", "year": 2013, "mimetype": "video/x-matroska", "container": "mkv",'+
    '"videoCodec": "h264", "other": ["Netflix"], "audioChannels": "5.1", "screenSize": "1080p", "type": "episode"}';
     {if AnsiPos('title',s) <> 0 then
     IsMovie := True
     else
     IsMovie := False;}

    L := Length(S);

    for I := 1 to L do
        Begin
            If (Ord(S[I]) <> 34)
            And (Ord(S[I]) <> 123)
            And (Ord(S[I]) <> 125)
            Then NS := NS + Copy(S,I,1);
        End;
        S := NS;
        NS := '';
        L := Length(S);

    for I := 1 to L do
        Begin
            If (Ord(S[I]) = 44)
            Or (Ord(S[I]) = 58)
            Then Begin
              NS := NS + #13#10;
              MM.Add(Trim(NS));
              NS := '';
            End
            Else NS := NS + Copy(S,I,1);
        End;
        MM.Add(Trim(NS));
//      --------------------------------------------------------------

        LN := MM.Count-1;
        for I := 0 to LN Do
        Begin
            If MM[I] = Trim('series')
            Then series := Trim(MM[I + 1]);
            If MM[I] = Trim('season')
            Then season := Trim(MM[I + 1]);
            If MM[I] = Trim('episodeNumber')
            Then episodeNumber := Trim(MM[I + 1]);
        End;

        ShowMessage(series+'.S'+season+'.E'+episodeNumber);

  finally
    MM.Free
  end;
end;
RepeatUntil
  • 2,272
  • 4
  • 32
  • 57