3

I want to assign a string with a json array. My code is:

JSONArray v;
JSONObject x,y,value;
....
x[L"x"]=new JSONValue((double)(i));
x[L"y"]=new JSONValue((double)(i));
value[L"value"]=new JSONValue((char*)(data));
v.push_back(new JSONValue(x));
v.push_back(new JSONValue(y));
v.push_back(new JSONValue(value));

all[i]->fruits->append(new JSONValue(v)); //error here,fruits is a string type

fruits is a string defined inside all.

I tried using push_back too but Its not working.

6
  • 2
    What the heck is an l in this code? What is fruits? Commented Aug 2, 2013 at 3:45
  • 1
    What JSON library are you using? Commented Aug 2, 2013 at 3:45
  • I am using simple json libray github.com/MJPA/SimpleJSON/tree/master/src Commented Aug 2, 2013 at 4:29
  • What exactly do you expect "appending" an array to a string to do? It's like saying you want to add 5 to apple. Commented Aug 2, 2013 at 4:39
  • 2
    I would, if I were you, reconsider your choice to use a library that requires such flippant use of new. Commented Aug 2, 2013 at 4:55

1 Answer 1

2

Assuming that fruits is a std::wstring you can use the Stringigy() member of JSONValue to do handle the conversion.

all[i]->fruits->append(JSONValue(v).Stringify());
Sign up to request clarification or add additional context in comments.

2 Comments

thanks it worked.do i have to delete any of the object.As i am running in a big for loop my process is getting aborted.I am getting pointed to deallocate(pointer_p,size_type).
For every new there needs to be a delete. At what point you call delete is really up to how you have organized your program and the requirements of the libraries you use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.