mirror of
https://github.com/openbullet/openbullet.git
synced 2023-10-21 07:33:42 -05:00
Added option for parsing JSON via JTokens (thanks ewwink).
This commit is contained in:
@@ -323,7 +323,7 @@ This will spawn and execute a Parse Block.
|
||||
Syntax:
|
||||
PARSE "TARGET" LR "LEFT" "RIGHT" [Recursive?] [EncodeOutput?] [CreateEmpty?] [UseRegexLR?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" CSS "SELECTOR" "ATTRIBUTE" [INDEX / Recursive?] [EncodeOutput?] [CreateEmpty?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" JSON "FIELD" [Recursive?] [EncodeOutput?] [CreateEmpty?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" JSON "FIELD" [JTokenParsing?] [Recursive?] [EncodeOutput?] [CreateEmpty?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" REGEX "REGEX" "OUTPUT" [Recursive?] [EncodeOutput?] [CreateEmpty?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -125,6 +125,7 @@
|
||||
<Label Content="Field Name:"/>
|
||||
<TextBox Text="{Binding JsonField, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</DockPanel>
|
||||
<CheckBox Content="Use JToken Parsing" IsChecked="{Binding JTokenParsing}" VerticalContentAlignment="Center" ToolTip="Allows navigating through fields using . for children and [i] or [*] for arrays"/>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<CheckBox Content="Recursive" IsChecked="{Binding Recursive}" VerticalContentAlignment="Center"/>
|
||||
<CheckBox Content="Encode Output" IsChecked="{Binding EncodeOutput}" VerticalContentAlignment="Center"/>
|
||||
|
||||
@@ -30,7 +30,7 @@ CAPTCHA "URL" [Base64?] [SendScreenshot?] -> VAR "NAME"
|
||||
<item name="PARSE">
|
||||
PARSE "TARGET" LR "LEFT" "RIGHT" [Recursive?] [EncodeOutput?] [CreateEmpty?] [UseRegexLR?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" CSS "SELECTOR" "ATTRIBUTE" [INDEX / Recursive?] [EncodeOutput?] [CreateEmpty?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" JSON "FIELD" [Recursive?] [EncodeOutput?] [CreateEmpty?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" JSON "FIELD" [JTokenParsing?] [Recursive?] [EncodeOutput?] [CreateEmpty?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
PARSE "TARGET" REGEX "REGEX" "OUTPUT" [Recursive?] [EncodeOutput?] [CreateEmpty?] -> VAR/CAP "NAME" ["PREFIX" "SUFFIX"]
|
||||
</item>
|
||||
<item name="UTILITY">
|
||||
|
||||
@@ -103,6 +103,10 @@ namespace RuriLib
|
||||
private string jsonField = "";
|
||||
/// <summary>The name of the json field for which we want to retrieve the value.</summary>
|
||||
public string JsonField { get { return jsonField; } set { jsonField = value; OnPropertyChanged(); } }
|
||||
|
||||
private bool jTokenParsing = false;
|
||||
/// <summary>Whether to parse the json object using jtoken paths.</summary>
|
||||
public bool JTokenParsing { get { return jTokenParsing; } set { jTokenParsing = value; OnPropertyChanged(); } }
|
||||
#endregion
|
||||
|
||||
#region REGEX
|
||||
@@ -239,6 +243,7 @@ namespace RuriLib
|
||||
case ParseType.JSON:
|
||||
writer
|
||||
.Literal(JsonField)
|
||||
.Boolean(JTokenParsing, "JTokenParsing")
|
||||
.Boolean(Recursive, "Recursive")
|
||||
.Boolean(EncodeOutput, "EncodeOutput")
|
||||
.Boolean(CreateEmpty, "CreateEmpty");
|
||||
@@ -428,11 +433,21 @@ namespace RuriLib
|
||||
break;
|
||||
|
||||
case ParseType.JSON:
|
||||
var jsonlist = new List<KeyValuePair<string, string>>();
|
||||
parseJSON("", original, jsonlist);
|
||||
foreach(var j in jsonlist)
|
||||
if (j.Key == ReplaceValues(jsonField, data))
|
||||
list.Add(j.Value);
|
||||
if (JTokenParsing)
|
||||
{
|
||||
JObject json = JObject.Parse(original);
|
||||
var jsonlist = json.SelectTokens(jsonField, false);
|
||||
foreach (var j in jsonlist)
|
||||
list.Add(j.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
var jsonlist = new List<KeyValuePair<string, string>>();
|
||||
parseJSON("", original, jsonlist);
|
||||
foreach (var j in jsonlist)
|
||||
if (j.Key == ReplaceValues(jsonField, data))
|
||||
list.Add(j.Value);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user