45 lines
1.5 KiB (Stored with Git LFS)
C#
45 lines
1.5 KiB (Stored with Git LFS)
C#
using System.Collections.Generic;
|
|
using Newtonsoft.Json.Linq;
|
|
using UnityEngine;
|
|
|
|
public static class GoogleSheetFetchHelper
|
|
{
|
|
public static List<(string Sheet, string Field, int RowIndex, string OldValue, string NewValue)> CompareJsonDiff(string oldJson, string newJson)
|
|
{
|
|
var result = new List<(string, string, int, string, string)>();
|
|
|
|
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++) // i = 1부터: 첫 줄은 주석
|
|
{
|
|
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((sheet.Key, prop.Name, i + 1, oldVal, newVal)); // i+1: 실제 시트에서의 행 번호 (1-based)
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
} |