Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Split a string into values

Split a string into values

Scheduled Pinned Locked Moved C#
comdata-structuresjsonhelptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Farhad Eft
    wrote on last edited by
    #1

    Hi, I receive a string from an API like this example: {"id":"30535","email":"myemail@yahoo.com","first_name":"John","last_name":"Smith","gender":"male","friends":{"data":[{"name":"Helen Ford","id":"68304"},{"name":"Leo Pitt","id":"4732"}] I'd like to split and save the values into these string personId string email string firstName string lastName string gender and for friends values into an array that contains these values "personId" and "name" (for each set of records) I'd really appreciate it if someone could help me.

    A L 2 Replies Last reply
    0
    • F Farhad Eft

      Hi, I receive a string from an API like this example: {"id":"30535","email":"myemail@yahoo.com","first_name":"John","last_name":"Smith","gender":"male","friends":{"data":[{"name":"Helen Ford","id":"68304"},{"name":"Leo Pitt","id":"4732"}] I'd like to split and save the values into these string personId string email string firstName string lastName string gender and for friends values into an array that contains these values "personId" and "name" (for each set of records) I'd really appreciate it if someone could help me.

      A Offline
      A Offline
      Abhipal Singh
      wrote on last edited by
      #2

      It looks like serialized JSON. You can deserialize it into and object and access the values easily (and also, you can assign those values into string variables if you want). There is a lot of material available on the internet regarding JSON handling in C# Check some links below to help you out with JSON deserialization: JSON example[^] Deserialize JSON with C#[^] http://stackoverflow.com/questions/22580141/json-newtonsoft-deserialize-object-containing-a-list-of-string[^]

      1 Reply Last reply
      0
      • F Farhad Eft

        Hi, I receive a string from an API like this example: {"id":"30535","email":"myemail@yahoo.com","first_name":"John","last_name":"Smith","gender":"male","friends":{"data":[{"name":"Helen Ford","id":"68304"},{"name":"Leo Pitt","id":"4732"}] I'd like to split and save the values into these string personId string email string firstName string lastName string gender and for friends values into an array that contains these values "personId" and "name" (for each set of records) I'd really appreciate it if someone could help me.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Refer below link, is this you are looking for - http://stackoverflow.com/questions/12676746/parse-json-string-in-c-sharp[^]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups