Alvin John Tandoc
Alvin John Tandoc

Reputation: 113

JSON missing Double Quotes iOS

I'm encountering a weird problem. I am parsing json data from our server. when I access it via my browser it shows this data:

productCombinationAttributes": [
    {
      "value": "Green",
      "price": "0",
      "img_id": "1005",
      "name": "color",
      "id": "b_9"
    },
    {
      "value": "Blue",
      "price": "0",
      "img_id": "1005",
      "name": "color",
      "id": "b_10"
    },
    {
      "value": "Yellow",
      "price": "0",
      "img_id": "1005",
      "name": "color",
      "id": "b_14"
    },
    {
      "value": "Xl",
      "price": "100",
      "img_id": "1005",
      "name": "size",
      "id": "b_11"
    },
    {
      "value": "L",
      "price": "50",
      "img_id": "1005",
      "name": "size",
      "id": "b_12"
    },
    {
      "value": "Metal",
      "price": "0.00",
      "img_id": "1005",
      "name": "material",
      "id": "b_13"
    }
  ],
  "productSpecification": [],
  "paymentMethod": [
    "Credit or Debit Card",
    "Paypal",
    "Dragon Pay",
    "Cash on Delivery"
  ],
  "productCombinatiobDetails": [
    {
      "quantity": "12",
      "combinationId": [
        "b_9",
        "b_12",
        "b_13"
      ],
      "id": 1519,
      "location": {
        "NCR": "100.0000",
        "Makati": "120.0000"
      }
    },
    {
      "quantity": "12",
      "combinationId": [
        "b_14",
        "b_11",
        "b_13"
      ],
      "id": 1520,
      "location": {
        "NCR": "100.0000",
        "Makati": "120.0000"
      }
    }
  ]

But when I access it via XCODE and parse it using afnetworking or other methods of parsing it. JSON looks like this:

productCombinationAttributes =     (
                {
            id = "b_9";
            "img_id" = 1005;
            name = color;
            price = 0;
            value = Green;
        },
                {
            id = "b_10";
            "img_id" = 1005;
            name = color;
            price = 0;
            value = Blue;
        },
                {
            id = "b_14";
            "img_id" = 1005;
            name = color;
            price = 0;
            value = Yellow;
        },
                {
            id = "b_11";
            "img_id" = 1005;
            name = size;
            price = 100;
            value = Xl;
        },
                {
            id = "b_12";
            "img_id" = 1005;
            name = size;
            price = 50;
            value = L;
        },
                {
            id = "b_13";
            "img_id" = 1005;
            name = material;
            price = "0.00";
            value = Metal;
        }
    );

Here's my code on parsing it:

   AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:[NSString stringWithFormat:@"url.com"] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"%@",responseObject);
        [self jsonParser:parentView scrollView:sv_parent];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Failure");
    }];

The problem is the double quotes are missing after i display the return data upon after my request. Can someone help me with this? thank you in advance :)

Upvotes: 1

Views: 2129

Answers (1)

Ken Kuan
Ken Kuan

Reputation: 798

That's not missing. Your print is [NSDictionary description] not a json string. AFHTTPRequestOperationManager already parsed json to NSDictionary for you. If you want to get origin json string, you can use [NSJSONSerialization dataWithJSONObject:options:error:] to serialize NSDictionary to json string.

NSData *data = [NSJSONSerialization dataWithJSONObject:responseObject options:0 error:nil];
NSString *jsonString = [NSString alloc] initWithData:data encoding: NSUTF8StringEncoding];

Upvotes: 1

Related Questions