コード例 #1
0
        public static string[] GetData2CSV(string url, string access_token)
        {
            string[]      result = new string[2];
            StringBuilder csv    = new StringBuilder();
            Dictionary <string, object> dictJSON = new Dictionary <string, object>();
            string json = REST.HttpGet(url + "&access_token=" + access_token);

            do
            {
                dictJSON = (Dictionary <string, object>)CountryCodeTopLevelDomain.DecodeJson(json);
                if (dictJSON.ContainsKey("error"))
                {
                    result[0] = "FAIL";
                    result[1] = ((Dictionary <string, object>)dictJSON["error"])["message"].ToString();
                    return(result);
                }

                ArrayList headers = (ArrayList)dictJSON["columnHeaders"];
                for (var i = 0; i < headers.Count; i++)
                {
                    var x = (Dictionary <string, object>)headers[i];
                    csv.Append(x["name"].ToString());
                    if (i < headers.Count - 1)
                    {
                        csv.Append(",");
                    }
                }

                csv.AppendLine();

                ArrayList rowData  = (ArrayList)dictJSON["rows"];
                int       rowLines = rowData.Count;
                for (var i = 0; i < rowLines; i++)
                {
                    string    line = string.Empty;
                    ArrayList row  = (ArrayList)rowData[i];
                    for (var j = 0; j < headers.Count; j++)
                    {
                        var s  = string.Empty;
                        var x  = (Dictionary <string, object>)headers[j];
                        var dt = x["dataType"].ToString();
                        if ("STRING" == dt)
                        {
                            s = "\"" + row[j].ToString() + "\"";
                        }
                        else
                        {
                            s = row[j].ToString();
                        }

                        line += s;
                        if (j < headers.Count - 1)
                        {
                            line += ",";
                        }
                    }

                    csv.AppendLine(line);
                }

                if (dictJSON.ContainsKey("nextLink"))
                {
                    json = REST.HttpGet(dictJSON["nextLink"].ToString() + "&access_token=" + access_token);
                }
                else
                {
                    break;
                }
            }while (true);
            result[0] = "OK";
            result[1] = csv.ToString();
            return(result);
        }
コード例 #2
0
 public static string GetData(string url, string access_token)
 {
     return(REST.HttpGet(url + "&access_token=" + access_token));
 }