Browsing 7239 questions and answers with Jon Skeet

How to convert json array to C# object array

i need a help, i try to convert Json array to C# object array, here is my json {"jsonString":"{\"MemberSeletedId\":[358753,358754]}"} and this is my c# object class : public...
Jon Skeet
people
quotationmark

Your property is declared as a single int - despite it being an array in the JSON. It looks like you should be deserializing the JSON to a single BOMembint[erSelectedID, but the MemberSeletedId property should be an int[] or... more 4/7/2015 9:35:40 AM

people

java.net.MalformedURLException: Protocol not found. Reason?

I am using this function : public void testing(String xml) throws ParserConfigurationException, SAXException, IOException{ Log.d("TAG"," root.getNodeName()"); ...
Jon Skeet
people
quotationmark

The problem is that you're passing in the XML content itself - but DocumentBuilder.parse(String) accepts a URL to load the XML from - not the content itself. You probably want to use DocumentBuilder.parse(InputSource) instead, having... more 4/6/2015 4:59:25 PM

people

how to access variables from private bodies in java

public void TheBank() { Scanner Sc = new Scanner(System.in); System.out.println("Please Enter your Username and Password"); MemoryStorage();// Stores the Username and...
Jon Skeet
people
quotationmark

Currently you're declaring local variables. Those only exist while you're executing the method. It sounds like they should actually be instance variables (fields) within your class: public class Whatever { private String username; ... more 4/6/2015 11:35:00 AM

people

Deserialize json string to object c#.net

I have a JSON string which needs to be deserialized into an object. This is what I have tried : Class : public class trn { public string visited_date { get; set; } ...
Jon Skeet
people
quotationmark

Your JSON represents an object with trn as a property within another object. So you need to represent that in your code, as well. For example: using System; using System.IO; using Newtonsoft.Json; public class Transaction { ... more 4/5/2015 4:56:38 PM

people

Construct a HashMap with specific value

I have a List of Module as below, and I try to construct a HashMap without a duplicate key, and the value is latest. DateTime start = new DateTime(2010, 5, 1, 12, 0, 0,...
Jon Skeet
people
quotationmark

The simplest way would just be to order by date (e.g. using a Comparator<Module>) and then just iterate: Map<String, DateTime> map = new HashMap<>(); for (Module module : sortedList) { map.put(module.getName(),... more 4/5/2015 7:41:54 AM

people

Conversion from java to c# Covariance and Contravariance

public interface IStorage<T> extends Iterable<T> { public void copyTo( IStorage<? super T> dest); public void copyFrom( IStorage<? extends...
Jon Skeet
people
quotationmark

Generic variance in C# is very different to generic variance in .NET. You sort of want something like this: public interface IStorage<out T> : IEnumerable<T> { // This won't compile - the constraint is on the wrong... more 4/4/2015 1:21:00 PM

people

Java abstract Number operator +=

I would like to create an abstract Vector3 class. So what I did was: class Vector3<T extends Number> {} And I have the 3 components: T x, y, z; However this way I...
Jon Skeet
people
quotationmark

But as far as I know the number classes are all inherited from the abstract Number class. Yes, but that's completely irrelevant when it comes to operators. You can't add operators overloads in Java at all, regardless of whether your... more 4/4/2015 11:46:16 AM

people

How do I print an Instant as rfc2822 in NodaTime?

I'm looking to print an Instant as rfc2822 in NodaTime. How? Quick search leads to broken google-code links. I'd prefer a built-in named pattern over supplying all formatting to...
Jon Skeet
people
quotationmark

I'd prefer a built-in named pattern over supplying all formatting to ToString. If you mean you're expecting a "standard" pattern so to speak, there isn't one. However, it's easy enough to write a custom pattern for this - giving you... more 4/4/2015 9:57:07 AM

people

Exception handling in java using finally

public class CheckProg { public int math(int i) { try { int result = i / 0; // throw new IOException("in here"); } catch (Exception e) { ...
Jon Skeet
people
quotationmark

Shouldn't the exception be caught before in the catch block and returned ? It is being caught, and that return statement is being executed... but then the return value is being effectively replaced by the return statement in the... more 4/3/2015 3:52:55 PM

people

How to output a list of numbers in an Arraylist without outputting the Brackets and Commas?

I have the following code used to help me find the prime numbers between 1 and whatever the user inputs. The only problem is, I have to output the numbers without the Brackets and...
Jon Skeet
people
quotationmark

Just output each value in turn. For example: // TODO: Rename PrimeFactor to primeFactors to follow Java naming conventions for (int value : PrimeFactor) { System.out.print(value); System.out.print(" "); // Or whatever separator... more 4/3/2015 12:58:53 AM

people