-1

i want to take 450

from the following:

NSString {status:0,val:450}

using objective c:

{status:0,val:450}

Please suggest me answer

Abhinandan Pratap
  • 2,142
  • 1
  • 18
  • 39
Nimmy
  • 47
  • 1
  • 5

1 Answers1

1

I cannot completely understand your question . I think you have you have an JSON data like:

{
status:0;
val:450;
}

If you want this data in your app. You want to do

    NSURL *blogURL = [NSURL URLWithString:@"https://your url here"];

    NSData *jsonData = [NSData dataWithContentsOfURL:blogURL];

    NSError *error = nil;

    NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];


    NSDictionary *data = [dataDictionary objectForKey:@"status"];

    NSDictionary *item = [data objectForKey:@"val"];

Your JSON Data get in Dictionary format. You can access the Data using the Key. In here your keys are status and val.

I hope this links are help for you. fetch parse json ios programming tutorial and this Link: json parsing in ios

Community
  • 1
  • 1
Sharat Kannan
  • 90
  • 2
  • 9
  • .ok can you explain what you want? – Sharat Kannan Apr 22 '16 at 04:58
  • i want to take 450 from the following: {status:0,val:450} its a String – Nimmy Apr 22 '16 at 05:01
  • NSString *strign = [[NSString alloc] initWithData:JsondataNew encoding:NSUTF8StringEncoding]; NSLOg : {status:0,val:641} – Nimmy Apr 22 '16 at 05:10
  • I more confused about the Code. Because converting JSON to String We cannot access the data. Because the JSON Data is like NSDictionary or NSData. If you try to Store the data in the NSDictionary. Then you can Easily access the Data using that key. – Sharat Kannan Apr 22 '16 at 05:28
  • Try this Hope this is a good and easy way. Convert the data to String It's very difficult to access the data. NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:JsondataNew options:0 error:&error]; NSDictionary *data = [dataDictionary objectForKey:@"status"]; NSDictionary *item = [data objectForKey:@"val"]; – Sharat Kannan Apr 22 '16 at 05:48
  • Thanks Brother : The problem was convert into dataDictionary value is null : this is because convert into NSString. My Response is like this : { URL: http://192./ } { status code: 200, headers { "Access-Control-Allow-Origin" = "*"; Connection = close; "Content-Length" = 18; "Content-Type" = "text/json"; } } – Nimmy Apr 22 '16 at 05:56
  • Sorry! I could not know how that was occurred. In this case want to do more process. Then only i can understand. Just Check the JSON Data is currently getting and do some google search how JSON parsing work . I hope you can understood very easily. Other way you want to give your code. Only that parsing happen. Then only I can help. – Sharat Kannan Apr 22 '16 at 06:10