kirannandedkar
asked on
getting error while converting to double
I want to convert jtoken value to double. How can i do it. here is code,
I get error as
How to resolve this? I get error on line
var responseStream = webRequest.GetResponse().GetResponseStream();
Encoding encode = System.Text.Encoding.Default;
using (StreamReader reader = new StreamReader(responseStream, encode))
{
JToken token = JObject.Parse(reader.ReadToEnd());
var pagination = token.SelectToken("pagination");
if (pagination != null && pagination.SelectToken("next_url") != null)
{
nextPageUrl = pagination.SelectToken("next_url").ToString();
}
else
{
nextPageUrl = null;
}
var images = token.SelectToken("data").ToArray();
foreach (var image in images)
{
imageUrl = image.SelectToken("images").SelectToken("standard_resolution").SelectToken("url").ToString();
if (String.IsNullOrEmpty(imageUrl))
Console.WriteLine("broken image URL");
var webClient = new WebClient();
byte[] imageBytes = webClient.DownloadData(imageUrl);
var imageId = image.SelectToken("id");
String sharePointSite = "http://mysite/";
String documentLibraryName = "myimage";
using (var site = new SPSite(sharePointSite))
{
using (SPWeb web = site.OpenWeb())
{
SPPictureLibrary addpics = (SPPictureLibrary)web.Lists[documentLibraryName];
SPFile file = addpics.RootFolder.Files.Add((string)imageId + ".bmp", imageBytes, true);
SPListItem item = file.Item;
var createdtime= image.SelectToken("created_time");
double mydoubleval = createdtime; // this line gives error
}
}
}
}
I get error as
cannot convert from 'Newtonsoft.Json.Linq.JToken' to 'double'
How to resolve this? I get error on line
double mydoubleval = createdtime; // this line gives error
http://www.newtonsoft.com/json/help/html/Operators_T_Newtonsoft_Json_Linq_JToken.htm
Conversions from JToken to other types are explicit.
Try casting:
Conversions from JToken to other types are explicit.
Try casting:
double mydoubleval = (double)createdtime;
ASKER
@louisfr i had tried that as well and i get error
Can not convert String to Double.
ASKER
@Gustav Brock i still get error after using convert.todouble
Then it probably isn't possible - at least using standard methods.
What does createdtime actually contain? As said, it sound like a timestamp and - if a string - you would have to convert that to DateTime first.
/gustav
What does createdtime actually contain? As said, it sound like a timestamp and - if a string - you would have to convert that to DateTime first.
/gustav
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
OK, as I suspected. Thanks for the feedback.
/gustav
/gustav
ASKER
I get unixtimestamp from instagram api. So used function UnixTimeStampToDateTime to convert to datetime.
Anyway, try with a specific convert:
Open in new window
/gustav