0

I have obtained the result from web service in string ResultedValue which is in loop as show in below code,

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;
    }
}

I want to store each value of the ResultedValue in any external JSON file format, when I am using

json = JsonConvert.SerializeObject(modified_listofstrings);

It gives me output as ["Target:Q1/2013:17"] in string itself, I don't know How I am going to store in external file, Since I am new to JSON I am not able to get it done, I would request to please provide me with any helping links

Reshma
  • 864
  • 5
  • 20
  • 38
  • What are you going to do with that `JSON` ? – Red Nov 12 '13 at 05:33
  • What form of output are you getting which you want to convert to JSON ?? – The_Lost_Avatar Nov 12 '13 at 05:34
  • actually I am getting 3 string values those are Target,Q1/2013,17..first is series,second is period and third is its value... I can take them individually or fuse them as Target:Q1/2013:17... my main aim is to plot a graph in highcharts where period is X-axis,values is y Axis and series will be plotted on graph...and my mandatory requirement is my values should be read from JSON format...so I want to save those values in JSON format in the way it will be easy for me to read.. I hope you understand – Reshma Nov 12 '13 at 05:39
  • @The_Lost_Avatar.. and the output I am getting before converting it to JSON is Target:Q1/2013:17... this is individual value, I can also get array of such kind of value indicating different series,its period id and it's value..but before converting it to JSON. – Reshma Nov 12 '13 at 05:43

1 Answers1

0

It is not pretty and may be not the right way but you can try it. Which language are you using BTW, this is how it is done in 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);

Just keep on putting the values like this. A bit of change is required if you want have any value that is a list i.e. [] or you have any {} nested within another {}

The_Lost_Avatar
  • 992
  • 5
  • 15
  • 35
  • I am using C# and how I am going to store in external txt file in JSON format – Reshma Nov 12 '13 at 06:06
  • http://stackoverflow.com/questions/17865584/convert-a-list-of-string-into-json-format, did you check this ?? http://stackoverflow.com/questions/4611031/convert-json-string-to-c-sharp-object – The_Lost_Avatar Nov 12 '13 at 06:10
  • I am getting string value in JSON format by using JsonConvert.SerializeObject.. which are get stored in string itslf but I want to store all those values in external txt file in json format itself from where I will read the values and plt the graph in highcharts. – Reshma Nov 12 '13 at 06:15
  • So write to a file like this System.IO.File.WriteAllText (@"C:\path.txt", things_you_want_to_write); A JSON format file is a .txt file only with Json inside it – The_Lost_Avatar Nov 12 '13 at 06:23
  • when I am trying to write then I am getting error access denied. – Reshma Nov 12 '13 at 06:51
  • You don't have the proper privileges i.e. you are not authorized to write . Try logging in from an admin account . Try writing in any other drive except for the C:/ drive. – The_Lost_Avatar Nov 12 '13 at 08:14
  • Sorry to update I have resolved that issue but I am trying to convert array of strings in JSON format and then trying to write in file and I am struggling with that, do u know the format that deals with the array of strings. – Reshma Nov 12 '13 at 08:53