|
Hehe You're welcome!
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
My XML data :
<xml>
<item>
<locationId>1</locationId>
<state></state>
<location>ABCD</location>
</item>
<item>
<locationId>2</locationId>
<state></state>
<location>EFGH</location>
</item>
</xml>
I need to parse this and retrieve the value of "locationId" and "location" alone.
Thanks in Advance.
|
|
|
|
|
See the System.Xml namespace.
|
|
|
|
|
Hi Guys,
Im having some trouble with JSON.
I need to retrieve the email value of each of a list of contacts, but am unable to do so.
string json = @"
{
'contacts': [
{
'vid': 154835,
'properties': {
'firstname': {
'value': 'HubSpot'
},
'lastname': {
'value': 'Test'
}
},
'identity-profiles': [
{
'vid': 154835,
'saved-at-timestamp': 1405347851237,
'deleted-changed-timestamp': 0,
'identities': [
{
'type': 'EMAIL',
'value': 'test@hubspot.com',
'timestamp': 1405347851180
},
{
'type': 'LEAD_GUID',
'value': 'c8f20860-d3d6-4b57-b092-86a07cebdcbc',
'timestamp': 1405347851237
}
]
}
],
'merge-audits': []
}
],
'has-more': true,
'vid-offset': 196189
}";
Above is one contact from a list of contacts.
Below is the code Im using to retrieve the required data.
Im able to retrieve firstname and lastname, but am unable to retrieve email.
Any suggestions as to how I can go about retrieving the email value?
dynamic data = JObject.Parse(strReader);
var vContacts = from i in (IEnumerable<dynamic>)data.contacts
select new
{
vid = i.vid,
firstname = i.properties.firstname.value,
lastname = i.properties.lastname.value,
email = (string)i.SelectToken("identity-profiles.identities.value")
};
Any help would be appreciated.
|
|
|
|
|
Please try this:
email = (string)i.SelectToken("identity-profiles[0].identities[0].value")
identity-profiles and identities are arrays, so you have to specify the index of the desired item.
See: http://www.newtonsoft.com/json/help/html/SelectToken.htm[^]
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Thats the second time in as many days that you've helped.
Sascha, thanks a lot, that worked.
dynamic data = JObject.Parse(strReader);
var vContacts = from i in (IEnumerable<dynamic>)data.contacts
select new
{
vid = i.vid,
firstname = i.properties.firstname.value,
lastname = i.properties.lastname.value,
email = i["identity-profiles"][0]["identities"][0]["value"]
};
|
|
|
|
|
You're welcome, glad I could help
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Psst you can up vote his answer with the little red GREEN arrow that appears on the left of the reply, that way his rep is enhanced.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Ah, I wasn't aware, thanks for letting me know.
|
|
|
|
|
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
So I have a web application for a time log management system. I have it to where you can create a timelog if you are an employee for the hours you have previously worked. I cannot figure out how to enable employees from entering in future work hours on the timelog entry and need some help please!
|
|
|
|
|
Member 11620437 wrote: I cannot figure out how to You need to provide technical details. How are we supposed to figure it out when knowing nothing about it beyond it's intended purpose?
- Put yourself in the shoes of someone trying to answer this. Can you really imagine anyone can? What are you expecting the answer to this could be?
- How does it not work? What did you do? What were you expecting, and what happened instead?
- Ask yourself: is there enough information for anybody who’s not you to figure out what the problem is?
- Notice how asking a question that is too vague will only get you more questions in return.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
modified 19-Apr-15 18:45pm.
|
|
|
|
|
Hi,
How can I add 3 objects to an array in C# ? I created 3 objects of a class and I want those three objects in an array in another class but I get the syntax wrong.
here in the main method I created 3 objects from Class student
static void Main(string[] args)
{
Student student1 = new Student
{
FirstName = "John",
LastName = "Wayne",
BirthDate = "26/05/1907"
};
Student student2 = new Student
{
FirstName = "Craig",
LastName = "Playstead",
BirthDate ="01/01/1967"
};
Student student3 = new Student
{
FirstName = "Paula",
LastName = "Smith",
BirthDate = "01/12/1977"
};
In another class I want to create an array and put the 3 student objects into it, how do I do that ? So far I only created an array[3]
Public class Course
{
private string courseName;
public string CourseName
{
get { return courseName; }
set { courseName = value; }
}
Student[] studentarray = new Student[3];
modified 19-Apr-15 14:35pm.
|
|
|
|
|
Very easy:
Student[] studentarray = new Student[3];
studentarray[0] = student1;
studentarray[1] = student2;
studentarray[2] = student3;
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
thanks, i got the syntax mixed up !
**edit., i get lots of errors when I try this
Error 1 Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
|
|
|
|
|
You're welcome!
Consider using a generic List instead of an array (if you don't use an array on purpose for some reason). It's way more flexible, e.g. allows dynamic growth in contrast to an array. Would look like this:
List<Student> students = new List<Student>();
students.Add(student1);
students.Add(student2);
students.Add(student3);
(put a using System.Collections.Generic; at the top of your source file.)
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
its not letting me add the objects to the array created.
studentarray[0] = student1;
Error: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
I created the 3 objects (of another class called Student) in the main method, I don't know if I can add the three objects from there ?
|
|
|
|
|
Please edit your question to include the code as you have it now, and the exact error message you are receiving.
|
|
|
|
|
I assume you've put the assignment into the class-scope, like so (15th line or so):
Public class Course
{
private string courseName;
public string CourseName
{
get { return courseName; }
set { courseName = value; }
}
Student[] studentarray = new Student[3];
studentarray[0] = student1;
public void SomeMethod()
{
studentarray[0] = student1;
}
public void SetStudent0(Student student)
{
studentarray[0] = student;
}
public void SetStudent(Student student, int index)
{
studentarray[index] = student;
}
private int ArrayCursor = 0;
public void AddStudent(Student student)
{
studentarray[ArrayCursor] = student;
ArrayCursor++;
}
private List<Student> Students = new List<Student>();
public void AddStudent(Student student)
{
Students.Add(student);
}
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace Assignment5
{
class Program
{
static void Main(string[] args)
{
// Create 3 students
Student student1 = new Student
{
FirstName = "John",
LastName = "Wayne",
BirthDate = "26/05/1907"
};
Student student2 = new Student
{
FirstName = "Craig",
LastName = "Playstead",
BirthDate ="01/01/1967"
};
Student student3 = new Student
{
FirstName = "Paula",
LastName = "Smith",
BirthDate = "01/12/1977"
};
// Create Teacher
Teacher teacher1 = new Teacher
{
TeacherfirstName = "Paul",
};
// Create course object
Course course = new Course();
course.CourseName = "Programming with C#.";
// Create degree object
Degree degree = new Degree();
degree.DegreeName = "Bachelor of Science Degree";
// Create Program object
UProgram uprogram = new UProgram();
uprogram.ProgramName = "Information Technology";
// count = GetActiveInstances(typeof(Student));
Console.WriteLine("The {0} program contains the {1} ", uprogram.ProgramName, degree.DegreeName);
Console.WriteLine("The {0} contains the course {1} ",degree.DegreeName, course.CourseName );
// Console.WriteLine("The {0} course contains students(s)" count);
Console.WriteLine("Count" + Student.count);
Console.Read();
}
public class Student
{
public static int count = 0;
public Student()
{
// Thread safe since this is a static property
Interlocked.Increment(ref count);
}
// use properties!
private string firstName;
// Get Set for FirstName
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
private string lastName;
// Get Set for LastName
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
private string birthDate;
// Get Set for BirthDate
public string BirthDate
{
get { return birthDate; }
set { birthDate = value; }
}
}
public class Teacher
{
private string teacherfirstName;
public string TeacherfirstName
{
get { return teacherfirstName; }
set { teacherfirstName = value; }
}
// string teacherlastName;
// string teacheroffice;
}
public class UProgram
{
private string programName;
public string ProgramName
{
get { return programName; }
set { programName = value; }
}
// string degreeOffered;
// string department;
}
public class Degree
{
private string courseName;
public string DegreeName
{
get { return courseName; }
set { courseName = value; }
}
}
public class Course
{
private string courseName;
public string CourseName
{
get { return courseName; }
set { courseName = value; }
}
Student[] studentarray = new Student[3];
studentarray[0] = student1;
// studentarray[1] = student2;
// studentarray[2] = student3;
Teacher[] teacherarray = new Teacher[3];
}
}
}
|
|
|
|
|
Yes - it's what I assumed it my last reply You inserted the assignment to array-index 0 directly within class-scope. It has to happen in a method (or, theoretically, in the constructor).
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
thanks for the post ! I will create a method and increment through the 3 students and add them, i will call the method outside the class
|
|
|
|
|
tá fáilte romhat
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
an-mhaith !!
|
|
|
|
|
Hi there.
I am making an application to manage data in some google spreadsheets.
I have all the References I need, and I can retrieve the data from spreadsheet decently I think, but how can I get all the data into my dataGridView properly?
I have low knowledge in C# generally, and virtually no experience with Google API, but I have sat down for hours now trying to figure it out.
I used this page[^] as a guide, but it doesn't contain any information whatsoever.
My code looks like this:
public Form1()
{
InitializeComponent();
SpreadsheetsService wsService = new SpreadsheetsService("testApp");
wsService.setUserCredentials("email@gmail.com", "password");
SpreadsheetQuery query = new SpreadsheetQuery();
SpreadsheetFeed feed = wsService.Query(query);
foreach (SpreadsheetEntry entry in feed.Entries)
{
comboBox1.Items.Add(entry.Title.Text.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
int sheetIndex = comboBox1.SelectedIndex;
SpreadsheetsService wsService = new SpreadsheetsService("testApp");
wsService.setUserCredentials("email@gmail.com", "password");
SpreadsheetQuery query = new SpreadsheetQuery();
SpreadsheetFeed feed = wsService.Query(query);
SpreadsheetEntry mySpreadsheet = (SpreadsheetEntry)feed.Entries[sheetIndex];
AtomLink link = mySpreadsheet.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, null);
WorksheetQuery wQuery = new WorksheetQuery(link.HRef.ToString());
WorksheetFeed wFeed = wsService.Query(wQuery);
WorksheetEntry worksheetEntry = (WorksheetEntry)wFeed.Entries[0];
AtomLink cLink = worksheetEntry.Links.FindService(GDataSpreadsheetsNameTable.CellRel, null);
CellQuery cQuery = new CellQuery(cLink.HRef.ToString());
CellFeed cFeed = wsService.Query(cQuery);
foreach (CellEntry curCell in cFeed.Entries)
{
Debug.WriteLine("The value on row {0} and column {1} is {2}", curCell.Cell.Row,
curCell.Cell.Column, curCell.Cell.Value);
}
}
I really appreciate your effort on helping me.
Thanks in advance!
|
|
|
|