getting error while converting to double

I want to convert jtoken value to double. How can i do it. here is code,
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


                                }
                            }

                            }

                        }

Open in new window



I get error as
 cannot convert from 'Newtonsoft.Json.Linq.JToken' to 'double'	

Open in new window


How to resolve this? I get error on line
                                   double mydoubleval = createdtime; // this line gives error

Open in new window

kirannandedkarAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
createdtime sounds like a timestamp, so why a double?
Anyway, try with a specific convert:
double mydoubleval = Convert.ToDouble(createdtime);

Open in new window

/gustav
0
louisfrCommented:
http://www.newtonsoft.com/json/help/html/Operators_T_Newtonsoft_Json_Linq_JToken.htm
Conversions from JToken to other types are explicit.
Try casting:
double mydoubleval = (double)createdtime;

Open in new window

0
kirannandedkarAuthor Commented:
@louisfr i had tried that as well and i get error  
Can not convert String to Double.

Open in new window

0
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

kirannandedkarAuthor Commented:
@Gustav Brock i still get error after using convert.todouble
0
Gustav BrockCIOCommented:
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
0
kirannandedkarAuthor Commented:
I managed to solve the problem

i used below

  var createdTime = image.SelectToken("created_time").Value<double>();
 double mydoubleval = imageCreatedTime;
 DateTime imgCreatedTime = UnixTimeStampToDateTime(mydoubleval);


   public static DateTime UnixTimeStampToDateTime(double unixTimeStamp)
        {
            // Unix timestamp is seconds past epoch
            System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
            dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToLocalTime();
            return dtDateTime;
        }
            

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gustav BrockCIOCommented:
OK, as I suspected. Thanks for the feedback.

/gustav
0
kirannandedkarAuthor Commented:
I get unixtimestamp from instagram api. So used function UnixTimeStampToDateTime to convert to datetime.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Images and Photos

From novice to tech pro — start learning today.