score:1
Accepted answer
//the call to webclient.downloadstring(string) will throw an exception if the
//uri does not exist, in your case, the json file does not exist
var alltext = null;
object jsonobject = null;
try
{
alltext = (new webclient()).downloadstring(uripath);
jsonobject = jsonconvert.deserializeobject(alltext);
}
catch(webexception ex)
{
jsonobject = new object[0];
}
score:0
icollection<int> readnumbersfromwebclient(int code)
{
// in case of exception: return empty string
try
{
string uripath = "http://mystorage.com/folder/" + code + ".json";
var downloadedtext = downloadtext(uripath);
return jsonconvert.deserializeobject<int[]>(alltext);
}
catch (exception exc) // or use specific exception
{
return new int[];
}
}
Source: stackoverflow.com
Related Query
- LINQ/MVC webservice return json file or an empty array
- How to convert a list of anonymous object to string array using linq for return using Json Result in ASP.NET MVC
- LINQ to return null if an array is empty
- How to I read a json file containing array with C# and perform LINQ query on it?
- How to return list linq in json in MVC Controller?
- LINQ Webservice GET list of similar products from JSON file
- LINQ C# to Array JSON Object in MVC
- Using a list of Json results as parameters for a mvc actionresult, to return objects from database with Linq and Lambda
- Execute an array of value in Linq to return the specific data in MVC Controller
- What does LINQ return when the results are empty
- Using C# Linq to return first index of null/empty occurrence in an array
- Return an empty collection when Linq where returns nothing
- Linq return string array
- How can I use linq to return integers in one array that do not match up with an integer property of another array?
- c# linq return a multidimensional array from linq
- Simple way to return anonymous types (to make MVC using LINQ possible)
- Count the number of children in my JSON file using JSON.NET with LINQ
- C# LINQ return counter array indices max to min
- LINQ to JSON - Query for object or an array
- LINQ to JSON group query on array
- c# - LINQ find 2D jagged array minimum, return index
- If a linq query returns empty does it return null?
- Can LINQ construct and return a multidimensional array
- How to get data in string array or JSON format using linq to entities?
- C# Linq .Select(int.parse) on empty array results in "Input string was not in a correct format"
- Clean way to return array indices matching a condition using LINQ
- How to return null when the Linq query returns empty value?
- Linq to Entity Framework return a list of parents with only a subset or empty collection of children
- Object format and return empty string in LINQ query
- JSON File and LINQ Sum and Group
More Query from same tag
- Getting selective tag values using LINQ
- Split a list of linq strings backwards for a search model
- C# link how to populate parent list with sublist from two related lists
- Can Someone Explain This MSDN Code To Me In English?
- Enumerable.OfType<>() not working as expected with route collection
- LINQ: How to skip one then take the rest of a sequence
- How do I identify which Linq functions will not call to sql multiple times?
- Get nodes from XML in C#
- Convert DataTable to LINQ Anonymous Type
- dirinfor.EnumerateFiles -> Error
- Retain DataGridView metadata after clearing DataSource
- Is there a difference between these two statements in Linq?
- matching string to item ids in LINQ
- Retrieving latest associated record in LINQ?
- LINQ - Join a table with another only when an outer condition satisfies
- How to serialize a raw json field?
- SQL query to LINQ expression - Entity Core Framework 3 + SQL Server
- C# string format unknown size
- C#: Is there a LINQ way to create an array of objects given an array of constructor parameters?
- How to transform 2-levels-deep foreach loop to LINQ expression to produce Dictionary<string,SomeList<Item>>?
- Write html anchor text (with name / value pair) to a string
- Can 't create extesion method for LINQ to Entities link DeleteAllOnSubmit() in LINQ to SQL
- How to retrieve the elements in list without using foreach loop in C#?
- FirstOrDefault giving wrong incorrect result
- Grabbing a specific value from a List of Entitiy
- C# Linq Datatable groupby datetime month
- Can I use a collection initializer with LINQ to return a fully populated collection?
- ADO.NET Entity Framework ObjectContext - Caching Question
- Linq query where First() appears to return null when results are not found
- How do I get this result using LINQ?