53 lines
1.7 KiB (Stored with Git LFS)
C#
53 lines
1.7 KiB (Stored with Git LFS)
C#
using System.Collections.Generic;
|
|
using Newtonsoft.Json.Linq;
|
|
using UnityEngine;
|
|
|
|
public static class GoogleSheetFetchHelper
|
|
{
|
|
public static List<GoogleSheetDiff> CompareJsonDiff(string oldJson, string newJson)
|
|
{
|
|
var result = new List<GoogleSheetDiff>();
|
|
|
|
if (string.IsNullOrEmpty(oldJson) || string.IsNullOrEmpty(newJson))
|
|
return result;
|
|
|
|
var oldObj = JObject.Parse(oldJson);
|
|
var newObj = JObject.Parse(newJson);
|
|
|
|
foreach (var sheet in newObj)
|
|
{
|
|
if (!oldObj.TryGetValue(sheet.Key, out var oldSheetData))
|
|
continue;
|
|
|
|
var newSheetData = (JArray)sheet.Value;
|
|
var oldSheetArray = (JArray)oldSheetData;
|
|
|
|
int minCount = Mathf.Min(oldSheetArray.Count, newSheetData.Count);
|
|
|
|
for (int i = 1; i < minCount; i++)
|
|
{
|
|
var oldRow = (JObject)oldSheetArray[i];
|
|
var newRow = (JObject)newSheetData[i];
|
|
|
|
foreach (var prop in newRow.Properties())
|
|
{
|
|
string oldVal = oldRow.TryGetValue(prop.Name, out var val) ? val.ToString() : "";
|
|
string newVal = prop.Value.ToString();
|
|
|
|
if (oldVal != newVal)
|
|
{
|
|
result.Add(new GoogleSheetDiff
|
|
{
|
|
Sheet = sheet.Key,
|
|
Field = prop.Name,
|
|
RowIndex = i + 1,
|
|
OldValue = oldVal,
|
|
NewValue = newVal
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
} |