Reputation: 386
I have deserialized a JSON string into arrays of current_location, EducationHistory and WorkHistory The problem i am encountering is that different people might have different specifications of education history and therefore increasing or decreasing the number of indexes in the array
How do i resolve dynamically this problem and store the values in the database
Edit:
Result soap = serializer.deserialize<Result>(ser);
foreach(var data in soap.data)
{
int lenght= soap.data.educationhistory.Length;
foreach(var education in soap.data.educationhistory)
{
// my insert query
}
}
Now the problem is I will have to run a foreach loop for work_history also. Two foreach loop inside a foreach loop is an issue. How can it be done in minimum use of loops??
Upvotes: 1
Views: 2428
Reputation: 1039498
You could check the length of the array:
int length = soap.data.education_history.Length; // gives you 2
Once you know the length you know that indexes must be smaller than this length. Of course if you simply loop through this array you won't have any problems with indexes:
foreach (var education in soap.data.education_history)
{
// TODO: save the education in your database
}
Upvotes: 1