0

我在循环中的字符串 ResultedValue 中从 Web 服务中获得了结果,如下面的代码所示,

for (int j = 0; j < value.Count; j++)
{
    var xmlAttributeCollection_for_period = value[i].Attributes;
    if (xmlAttributeCollection != null)
    {
        var periodid = xmlAttributeCollection_for_period["periodid"];
        xmlActions[i] = periodid.Value;
        period_final_id = periodid.Value;
        string period_name = Client.GetAttributeAsString(
                                            sessionId, periodid.Value, "name", "");

        var action = xmlAttributeCollection_for_period["value"];
        xmlActionsone[i] = action.Value;
        period_final_value = action.Value;

        values += final_resulted_series_name+":"+period_name + ":" 
                                                        + action.Value + ",";
        string vals = values.Split(',')[1];
        counts = values;
        string[] periods = counts.Split(',');
        Period1 = periods[i];
        // string final_resulted_period_name = Client.GetAttributeAsString(sessionId, resulted_series_id, "name", "");

        resulted_value = final_resulted_series_name + ":" + period_name 
                                                    + ":" + period_final_value;

        modified_listofstrings.Add(resulted_value);

        json = JsonConvert.SerializeObject(modified_listofstrings);
        //changed_json = json;
    }
}

我想在使用时以任何外部 JSON 文件格式存储 ResultedValue 的每个值

json = JsonConvert.SerializeObject(modified_listofstrings);

它在字符串本身中给我输出为 ["Target:Q1/2013:17"],我不知道我将如何存储在外部文件中,因为我是 JSON 新手,所以我无法完成它,我会要求请向我提供任何帮助链接

4

1 回答 1

0

它不漂亮,可能不是正确的方法,但你可以试试。顺便说一句,您使用哪种语言,这是在 Java 中完成的。

//Get this library and import it
import org.json.simple.JSONObject;
//Sample JSON query {'set_boot': True, 'synchronous': True }
JSONObject json = new JSONObject();

json.put("set_boot" , true);
json.put("synchronous", true);

继续把这样的价值观。如果您想要任何值是一个列表,即 [] 或者您有任何 {} 嵌套在另一个 {} 中,则需要进行一些更改

于 2013-11-12T06:03:32.420 回答