Skip to content

Commit 6b995b0

Browse files
committed
refac: update jsonResponse parsing logic
1 parent 8fa78d1 commit 6b995b0

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

Assets/Adjust/Scripts/AdjustAttribution.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,12 @@ public AdjustAttribution(string jsonString)
5151
this.CostCurrency = AdjustUtils.GetJsonString(jsonNode, AdjustUtils.KeyCostCurrency);
5252
this.FbInstallReferrer = AdjustUtils.GetJsonString(jsonNode, AdjustUtils.KeyFbInstallReferrer);
5353

54-
var jsonResponseNode = jsonNode[AdjustUtils.KeyJsonResponse];
55-
if (jsonResponseNode == null)
54+
var jsonResponseValue = jsonNode[AdjustUtils.KeyJsonResponse];
55+
if (jsonResponseValue == null)
5656
{
5757
return;
5858
}
59-
if (jsonResponseNode.AsObject == null)
60-
{
61-
return;
62-
}
63-
64-
this.JsonResponse = new Dictionary<string, object>();
65-
AdjustUtils.WriteJsonResponseDictionary(jsonResponseNode.AsObject, this.JsonResponse);
59+
this.JsonResponse = AdjustUtils.GetAttributionJsonResponse(jsonResponseValue);
6660
}
6761

6862
public AdjustAttribution(Dictionary<string, string> dicAttributionData)

Assets/Adjust/Scripts/AdjustUtils.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,22 @@ public static Dictionary<string, string> GetSkanUpdateDataDictionary(string skan
350350
return skanUpdateDataDictionary;
351351
}
352352

353+
public static Dictionary<string, object> GetAttributionJsonResponse(string attributionJsonResponse)
354+
{
355+
Dictionary<string, object> attributionJsonResponseDictionary = new Dictionary<string, object>();
356+
var attributionJsonResponseNode = JSON.Parse(attributionJsonResponse);
357+
if (attributionJsonResponseNode != null && attributionJsonResponseNode.AsObject != null)
358+
{
359+
Dictionary<string, object> temp = new Dictionary<string, object>();
360+
AdjustUtils.WriteJsonResponseDictionary(attributionJsonResponseNode.AsObject, temp);
361+
foreach (KeyValuePair<string, object> entry in temp)
362+
{
363+
attributionJsonResponseDictionary.Add(entry.Key, entry.Value);
364+
}
365+
}
366+
return attributionJsonResponseDictionary;
367+
}
368+
353369
public static string GetValueOrEmptyToNull(string value)
354370
{
355371
return string.IsNullOrEmpty(value) ? null : value;

Assets/Test/Scripts/CommandExecutor.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,16 @@ private void Config()
369369
_testLibrary.AddInfoToSend("cost_amount", attribution.CostAmount.ToString());
370370
_testLibrary.AddInfoToSend("cost_currency", attribution.CostCurrency);
371371
_testLibrary.AddInfoToSend("fb_install_referrer", attribution.FbInstallReferrer);
372-
var updatedJsonResponse = new Dictionary<string, object>(attribution.JsonResponse);
373372
#if UNITY_IOS
374-
updatedJsonResponse.Remove("fb_install_referrer");
375-
if (updatedJsonResponse.TryGetValue("cost_amount", out var costAmount) && costAmount is IConvertible)
373+
var updatedJsonResponse = new Dictionary<string, object>();
374+
if (attribution.JsonResponse != null)
376375
{
377-
updatedJsonResponse["cost_amount"] = string.Format("{0:0.00}", System.Convert.ToDouble(costAmount));
376+
updatedJsonResponse = new Dictionary<string, object>(attribution.JsonResponse);
377+
updatedJsonResponse.Remove("fb_install_referrer");
378+
if (updatedJsonResponse.TryGetValue("cost_amount", out var costAmount) && costAmount is IConvertible)
379+
{
380+
updatedJsonResponse["cost_amount"] = string.Format("{0:0.00}", System.Convert.ToDouble(costAmount));
381+
}
378382
}
379383
_testLibrary.AddInfoToSend("json_response", JsonConvert.SerializeObject(updatedJsonResponse));
380384
#else
@@ -974,12 +978,16 @@ private void AttributionGetter()
974978
_testLibrary.AddInfoToSend("cost_amount", attribution.CostAmount.ToString());
975979
_testLibrary.AddInfoToSend("cost_currency", attribution.CostCurrency);
976980
_testLibrary.AddInfoToSend("fb_install_referrer", attribution.FbInstallReferrer);
977-
var updatedJsonResponse = new Dictionary<string, object>(attribution.JsonResponse);
978981
#if UNITY_IOS
979-
updatedJsonResponse.Remove("fb_install_referrer");
980-
if (updatedJsonResponse.TryGetValue("cost_amount", out var costAmount) && costAmount is IConvertible)
982+
var updatedJsonResponse = new Dictionary<string, object>();
983+
if (attribution.JsonResponse != null)
981984
{
982-
updatedJsonResponse["cost_amount"] = string.Format("{0:0.00}", System.Convert.ToDouble(costAmount));
985+
updatedJsonResponse = new Dictionary<string, object>(attribution.JsonResponse);
986+
updatedJsonResponse.Remove("fb_install_referrer");
987+
if (updatedJsonResponse.TryGetValue("cost_amount", out var costAmount) && costAmount is IConvertible)
988+
{
989+
updatedJsonResponse["cost_amount"] = string.Format("{0:0.00}", System.Convert.ToDouble(costAmount));
990+
}
983991
}
984992
_testLibrary.AddInfoToSend("json_response", JsonConvert.SerializeObject(updatedJsonResponse));
985993
#else

0 commit comments

Comments
 (0)