40000 linier af 100 bytes er kun 4 MB og kan sagtens være i memory og så er det nemt at parse.
Min anbefaling til C# (eller VB.NET= er Newtonsoft.JSON (kan hentes med NuGet).
JSON inputÆ
[
{
"ClassName": "Desc_Water_C",
"mDecalSize": "200.000000",
"mPingColor": "(R=0.000000,G=0.000000,B=0.000000,A=0.000000)",
"mCollectSpeedMultiplier": "1.000000",
"mManualMiningAudioName": "Metal",
"mDisplayName": "Water",
"mDescription": "It's water.",
"mAbbreviatedDisplayName": "H2O",
"mStackSize": "SS_FLUID",
"mCanBeDiscarded": "True",
"mRememberPickUp": "False",
"mEnergyValue": "0.000000",
"mRadioactiveDecay": "0.000000",
"mForm": "RF_LIQUID",
"mSmallIcon": "Texture2D /Game/FactoryGame/Resource/RawResources/Water/UI/LiquidWater_Pipe_256.LiquidWater_Pipe_256",
"mPersistentBigIcon": "Texture2D /Game/FactoryGame/Resource/RawResources/Water/UI/LiquidWater_Pipe_512.LiquidWater_Pipe_512",
"mSubCategories": "",
"mMenuPriority": "0.000000",
"mFluidColor": "(B=212,G=176,R=122,A=255)",
"mGasColor": "(B=0,G=0,R=0,A=0)",
"mResourceSinkPoints": "5",
"mBuildMenuPriority": "0.000000"
},
{
"ClassName": "Desc_OreIron_C",
"mDecalSize": "200.000000",
"mPingColor": "(R=0.460000,G=0.291200,B=0.242434,A=1.000000)",
"mCollectSpeedMultiplier": "1.000000",
"mManualMiningAudioName": "Metal",
"mDisplayName": "Iron Ore",
"mDescription": "Used for crafting.\r\nThe most essential basic resource.",
"mAbbreviatedDisplayName": "Iron",
"mStackSize": "SS_MEDIUM",
"mCanBeDiscarded": "True",
"mRememberPickUp": "True",
"mEnergyValue": "0.000000",
"mRadioactiveDecay": "0.000000",
"mForm": "RF_SOLID",
"mSmallIcon": "Texture2D /Game/FactoryGame/Resource/RawResources/Nodes/UI/IconDesc_iron_new_64.IconDesc_iron_new_64",
"mPersistentBigIcon": "Texture2D /Game/FactoryGame/Resource/RawResources/Nodes/UI/IconDesc_iron_new_256.IconDesc_iron_new_256",
"mSubCategories": "",
"mMenuPriority": "0.000000",
"mFluidColor": "(B=0,G=0,R=0,A=0)",
"mGasColor": "(B=0,G=0,R=0,A=0)",
"mResourceSinkPoints": "1",
"mBuildMenuPriority": "0.000000"
}
]
Parse kendte felter:
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace E
{
public class Program
{
public static void Main(string[] args)
{
JArray all = (JArray)JsonConvert.DeserializeObject(File.ReadAllText(@"\work\e.json"));
foreach(JObject one in all)
{
Console.WriteLine("**** start object ****");
Console.WriteLine("ClassName = {0}", one.Value<string>("ClassName"));
Console.WriteLine("mDecalSize = {0}", one.Value<string>("mDecalSize"));
Console.WriteLine("mPingColor = {0}", one.Value<string>("mPingColor"));
}
Console.ReadKey();
}
}
}
output:
**** start object ****
ClassName = Desc_Water_C
mDecalSize = 200.000000
mPingColor = (R=0.000000,G=0.000000,B=0.000000,A=0.000000)
**** start object ****
ClassName = Desc_OreIron_C
mDecalSize = 200.000000
mPingColor = (R=0.460000,G=0.291200,B=0.242434,A=1.000000)
Parse alle felter:
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace E
{
public class Program
{
public static void Main(string[] args)
{
JArray all = (JArray)JsonConvert.DeserializeObject(File.ReadAllText(@"\work\e.json"));
foreach(JObject one in all)
{
Console.WriteLine("**** start object ****");
foreach(KeyValuePair<string,JToken> f in one)
{
Console.WriteLine("field name = {0}, field value = {1}", f.Key, (string)f.Value);
}
}
Console.ReadKey();
}
}
}
output:
**** start object ****
field name = ClassName, field value = Desc_Water_C
field name = mDecalSize, field value = 200.000000
field name = mPingColor, field value = (R=0.000000,G=0.000000,B=0.000000,A=0.00
0000)
field name = mCollectSpeedMultiplier, field value = 1.000000
field name = mManualMiningAudioName, field value = Metal
field name = mDisplayName, field value = Water
field name = mDescription, field value = It's water.
field name = mAbbreviatedDisplayName, field value = H2O
field name = mStackSize, field value = SS_FLUID
field name = mCanBeDiscarded, field value = True
field name = mRememberPickUp, field value = False
field name = mEnergyValue, field value = 0.000000
field name = mRadioactiveDecay, field value = 0.000000
field name = mForm, field value = RF_LIQUID
field name = mSmallIcon, field value = Texture2D /Game/FactoryGame/Resource/Raw
Resources/Water/UI/LiquidWater_Pipe_256.LiquidWater_Pipe_256
field name = mPersistentBigIcon, field value = Texture2D /Game/FactoryGame/Reso
urce/RawResources/Water/UI/LiquidWater_Pipe_512.LiquidWater_Pipe_512
field name = mSubCategories, field value =
field name = mMenuPriority, field value = 0.000000
field name = mFluidColor, field value = (B=212,G=176,R=122,A=255)
field name = mGasColor, field value = (B=0,G=0,R=0,A=0)
field name = mResourceSinkPoints, field value = 5
field name = mBuildMenuPriority, field value = 0.000000
**** start object ****
field name = ClassName, field value = Desc_OreIron_C
field name = mDecalSize, field value = 200.000000
field name = mPingColor, field value = (R=0.460000,G=0.291200,B=0.242434,A=1.00
0000)
field name = mCollectSpeedMultiplier, field value = 1.000000
field name = mManualMiningAudioName, field value = Metal
field name = mDisplayName, field value = Iron Ore
field name = mDescription, field value = Used for crafting.
The most essential basic resource.
field name = mAbbreviatedDisplayName, field value = Iron
field name = mStackSize, field value = SS_MEDIUM
field name = mCanBeDiscarded, field value = True
field name = mRememberPickUp, field value = True
field name = mEnergyValue, field value = 0.000000
field name = mRadioactiveDecay, field value = 0.000000
field name = mForm, field value = RF_SOLID
field name = mSmallIcon, field value = Texture2D /Game/FactoryGame/Resource/Raw
Resources/Nodes/UI/IconDesc_iron_new_64.IconDesc_iron_new_64
field name = mPersistentBigIcon, field value = Texture2D /Game/FactoryGame/Reso
urce/RawResources/Nodes/UI/IconDesc_iron_new_256.IconDesc_iron_new_256
field name = mSubCategories, field value =
field name = mMenuPriority, field value = 0.000000
field name = mFluidColor, field value = (B=0,G=0,R=0,A=0)
field name = mGasColor, field value = (B=0,G=0,R=0,A=0)
field name = mResourceSinkPoints, field value = 1
field name = mBuildMenuPriority, field value = 0.000000