I'm having some issues with fetching json values in c#.

http://i.stack.imgur.com/Uxn8e.png

Here is the code in question:

var json2 = new WebClient().DownloadString("http://fetch.json.url.here" + Input_Textbox.Text);
JObject o2 = JObject.Parse(json2);

string he_ident = (string)o2["he_ident"];
string le_ident = (string)o2["le_ident"];

Console.WriteLine(he_ident);
Console.WriteLine(le_ident);


Line 204 is: JObject o2 = JObject.Parse(json2);

The json is this: [{"le_ident":"06L","he_ident":"24R"},{"le_ident":"06R","he_ident":"24L"},{"le_ident":"07L","he_ident":"25R"},{"le_ident":"07R","he_ident":"25L"}]

I've also tried with just one set of le_ident and he_ident, such as [{"le_ident":"06L","he_ident":"24R"}] but it sill throws the same error.

Any ideas?


Question: How to create an entity with a composite primary key containing a generated value
Answer: Do as follows whether you want this kind of behavior (You nedd to use property access instead of field one) 

Parent.class (Notice a property of Type MutableInt and addChild as a way to set up both sides)

@Entity
public class Parent implements Serializable {

    private MutableInt id = new MutableInt();

    private List&lt;Child&gt; childList = new ArrayList();

    @OneToMany(mappedBy="parent")
    @JoinColumn(name="PARENT_ID", insertable=false, updatable=false)
    @Cascade(CascadeType.SAVE_UPDATE)
    public List&lt;Child&gt; getChildList() {
        return childList;
    }

    public void setChildList(List&lt;Child&gt; childList) {
        this.childList = childList;
    }

    @Id
    @GeneratedValue
    public Integer getId() {
        return id.intValue();
    }

    public void setId(Integer id) {
        this.id.setValue(id);
    }

    @Transient
    public MutableInt getIdAsMutableInt() {
        return id;
    }

    /**
     * Add convenience method 
     * 
     * A way to set up both sides (You have a bi-directional relationship, right ???)
     */
    public void addChild(Child child) {
        if(child.getChildId() == null)
            child.setChildId(new Child.ChildId());

        child.getChildId().setParentIdAsMutableInt(id);

        getChildList().add(child);

        child.setParent(this);
    }

}


Child.class (Notice static inner class )

@Entity
public class Child implements Serializable {

    private ChildId childId;

    private Parent parent;

    @EmbeddedId
    public ChildId getChildId() {
        return childId;
    }

    public void setChildId(ChildId childId) {
        this.childId = childId;
    }

    @ManyToOne
    @JoinColumn(name="PARENT_ID", insertable=false, updatable=false)
    public Parent getParent() {
        return parent;
    }

    public void setParent(Parent parent) {
        this.parent = parent;
    }

    /**
      * Composite primary key class MUST override equals and hashCode
      */
    @Embeddable
    public static class ChildId implements Serializable {

        private MutableInt parentId = new MutableInt();

        private Integer chId;

        public void setParentIdAsMutableInt(MutableInt parentId) {
            this.parentId = parentId;
        }

        @GeneratedValue
        public Integer getChId() {
            return chId;
        }

        public void setChId(Integer chId) {
            this.chId = chId;
        }

        @Column(name="PARENT_ID")
        public Integer getParentId() {
            return parentId.intValue();
        }

        public void setParentId(Integer parentId) {
            this.parentId.setValue(parentId);
        }

        @Override
        public boolean equals(Object o) {
            if(!(o instanceof ChildId))
                return false;

            final ChildId other = (ChildId) o;
            return new EqualsBuilder()
                       .append(getChId(), other.getChId())
                       .append(getParentId(), other.getParentId()).isEquals();
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 11 * hash + getParentId().hashCode();
            hash = 11 * hash + getChId().hashCode();
            return hash;
        }

    }

}


And to test

Session session = configuration.buildSessionFactory().openSession();
session.beginTransaction();

Parent parent = new Parent();
parent.addChild(new Child());

session.save(parent);

session.getTransaction().commit();


You need a MutableInt because of Integer is immutable instance. But your MutableInt field is encapsulated by a Integer property. See carefully