Hi, you are right the problem is not at this particular line:-
JObject result = JObject.Parse(ssJSONin);
But I believe is somewhere when I am trying to handle the type JTokenType.Array. Below is my full code. This code is trying to run trough the full JSON and if any string value is more than 50 chars it does a substring and restrict it to 50 chars:-
public void MssParseDocument(string ssJSONin, out string ssJSONout) {
ssJSONout = "";
JObject result = JObject.Parse(ssJSONin);
foreach (JProperty property in result.Properties()) {
processJProperty(property);
}
ssJSONout = JsonConvert.SerializeObject(result, Formatting.None);
} // MssParseDocument
private void processJProperty(JProperty property) {
if (property.Value == null)
{
return;
}
if (property.Value.Type == JTokenType.String)
{
if (property.Value.ToString().Length > 50)
{
property.Value = property.Value.ToString().Substring(0, 50);
}
}
else if (property.Value.Type == JTokenType.Object)
{
foreach (JToken innerProperty in property.Children())
{
//processJProperty(innerProperty);
JObject obj = (JObject)innerProperty;
foreach (JProperty p in obj.Properties())
{
processJProperty(p);
}
}
}
else if (property.Value.Type == JTokenType.Array)
{
JArray array = (JArray) property.Value;
foreach (JToken innerProperty in array.Children()) {
if (innerProperty.Type == JTokenType.String) {
innerProperty.ToString();
JValue value = (JValue) innerProperty;
if (value.Value.ToString().Length > 50)
{
value.Value = value.Value.ToString().Substring(0, 50);
}
} else {
JObject obj = (JObject)innerProperty;
foreach (JProperty p in obj.Properties())
{
processJProperty(p);
}
}
}
}
}